Dynamically adding DataGrid columns

I

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>
</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>
 
A

Alvin Bruney [MVP]

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
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top