Create ItemTemplates at runtime

G

Gordon

Hi,

Fairly new to ASP.net. I want to create a Datagrid that will bind to a
DataSet created a runtime and which will hence have a variable number of
columns. I want to show the data in binded textboxes.
I can't create template columns in the designer because I don't know the
number and column name but I can see how to do it at runtime ie in Page_Init
for (int counter=0;counter<dataSet1.Columns.count; counter++) {
TemplateColumn dc = new TemplateColumn()
dc.HeadText = dataset1.Columns[counter].ColumnName
DataGrid1.Columns.Add(dc)
}

but I'm a bit lost on how to add an ItemTemplate which has a bound textbox
to each TemplateColumn as I create them
 
M

msnews.microsoft.com

Gordon said:
Hi,

Fairly new to ASP.net. I want to create a Datagrid that will bind to a
DataSet created a runtime and which will hence have a variable number of
columns. I want to show the data in binded textboxes.
I can't create template columns in the designer because I don't know the
number and column name but I can see how to do it at runtime ie in
Page_Init
for (int counter=0;counter<dataSet1.Columns.count; counter++) {
TemplateColumn dc = new TemplateColumn()
dc.HeadText = dataset1.Columns[counter].ColumnName
DataGrid1.Columns.Add(dc)
}

but I'm a bit lost on how to add an ItemTemplate which has a bound textbox
to each TemplateColumn as I create them

Hi Gordon,

I have a sample that adds checkboxes and dropdownlists to a customized
template at runtime.
http://www.societopia.net/Samples/DataGridEventDelegates.aspx

The process of adding a textbox is not different.

HTH,
Phillip Williams
http://www.webswapp.com
http://www.societopia.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top