Discussion:
Dynamically adding DataGrid columns
(too old to reply)
Ian Oldbury
2005-02-08 10:59:50 UTC
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]
2005-02-08 14:19:17 UTC
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
----------------------------------------------------------
Post by Ian Oldbury
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>
Loading...