Dynamically adding DataGrid columns

Discussion in 'ASP .Net Datagrid Control' started by Ian Oldbury, Feb 8, 2005.

  1. Ian Oldbury

    Ian Oldbury Guest

    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>
    Ian Oldbury, Feb 8, 2005
    #1
    1. Advertising

  2. 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
    ----------------------------------------------------------


    "Ian Oldbury" <ian_oldbury@_NO_msn_SPAM_.com> wrote in message
    news:%...
    > 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], Feb 8, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keithb
    Replies:
    0
    Views:
    2,219
    keithb
    May 4, 2006
  2. herman404
    Replies:
    1
    Views:
    444
    =?Utf-8?B?c2xlbWVu?=
    Jun 20, 2006
  3. rob thomson
    Replies:
    0
    Views:
    253
    rob thomson
    Sep 4, 2003
  4. Sal

    Adding Columns to Datagrid Dynamically

    Sal, Feb 26, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    122
  5. ton
    Replies:
    2
    Views:
    200
    Alvin Bruney [MVP]
    Feb 11, 2004
Loading...

Share This Page