ASP.net programatically generate template columns

Murray Brown
Murray Brown used Ask the Experts™
on
Hi

In my ASP.net web app I bind a datatable to a GridView. The number of columns in the datatable differs each time so I can't manually create
template textbox columns. Is it possible to dynamically create textbox columns for every second column.?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Developer User Interface
Commented:
If you do not set the autogenerate to true u will have to manually add all the columns. I don’t think only by adding every second column as template column will work.

Try this

for(i=0; i< dt.Columns.Count;i++)
{
  TemplateField tf = new TemplateField();
Gv.Columns.Add(tf);
}
Murray BrownASP.net/VSTO Developer

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial