Search code examples
asp.netdetailsviewtemplatefield

Adding TemplateField to DetailsView


How do I add TemplateField control to the beginning of the DetailsView Fields collection?

Here is my code..

TemplateField tf = new TemplateField();
...
...
dv.Fields.Add(tf);

This adds to the very end of the DetailsView control. I tried dv.Fields(0) but there is no Add method available. I noticed that we have dv.Fields.RemoveAt but we do not have dv.Fields.AddAt...

Any ideas???


Solution

  • To Add the field at the beginning, use the INSERT method as follows:

    TemplateField tf = new TemplateField();
    ...
    ...
    dv.Fields.Insert(0, tf);