2

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???

dotnet-practitioner
  • 13,968
  • 36
  • 127
  • 200

1 Answers1

2

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

TemplateField tf = new TemplateField();
...
...
dv.Fields.Insert(0, tf);
Jose Basilio
  • 50,714
  • 13
  • 121
  • 117