Discussion:
Dynamically adding DataGrid columns
(too old to reply)
Ian Oldbury
20 years ago
Permalink
Hi,

Does anyone know how to add columns dynamically to a DataGrid.

i populate the grid using the .ItemDataBound

the current structure of my grids are as below....

<asp:templatecolumn>
<headertemplate>
<asp:label id="lblDisp" runat="server" text="" tooltip="" />
</headertemplate>
<itemtemplate>
<asp:label id="lblSales" runat="server" cssclass="GridTDText"></asp:label>
<br />
<asp:label id="lblProfit" runat="server"
cssclass="GridTDText"></asp:label>
<br />
<asp:label id="lblMargin" runat="server"
cssclass="GridTDText"></asp:label>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="txtSales" runat="server" cssclass="GridTextBox Small"
</asp:textbox>
<br />
<asp:textbox id="txtProfit" runat="server" cssclass="GridTextBox
Small"></asp:textbox>
<br />
<asp:textbox id="txtMargin" runat="server" cssclass="GridTextBox
Small"></asp:textbox>
</edititemtemplate>
</asp:templatecolumn>
Alvin Bruney [MVP]
20 years ago
Permalink
One approach is to simply add an extra column to your dataset and then bind
the dataset to the datagrid. The extra column would then show up
automatically.
--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://tinyurl.com/27cok
----------------------------------------------------------
...
Continue reading on narkive:
Search results for 'Dynamically adding DataGrid columns' (Questions and Answers)
5
replies
can i get question answer of asp.net ?
started 19 years ago
software
Loading...