How can I dynamically add a control to a DataGrid Template column?

Discussion in 'ASP .Net Datagrid Control' started by Richard, Aug 6, 2004.

  1. Richard

    Richard Guest

    I want to do the following:

    // create the template column ...
    TemplateColumn tc = new TemplateColumn();
    tc.HeaderText = "Location";
    tc.HeaderStyle.Width = Unit.Percentage(40);

    // create a label for the item template ...
    label = new Label();
    label.ID = "lbl" + Tree + "Location";
    label.Text = "<%# DataBinder.Eval(Container.DataItem, 'Location') %>";

    // Add the label to the template column
    ??? The unlike the dataGrid.Columns, the template column has no
    Add method so how do I add the control ???

    dataGrid.Columns.Add(tc);


    The area where the ??? are is where I need help. Any help would be appreciated.

    Thanks
    Richard, Aug 6, 2004
    #1
    1. Advertising

  2. Richard

    Rick Spiewak Guest

    Take a look at the ITemplate interface definition, it should show you the
    way.

    "Richard" <> wrote in message
    news:...
    > I want to do the following:
    >
    > // create the template column ...
    > TemplateColumn tc = new TemplateColumn();
    > tc.HeaderText = "Location";
    > tc.HeaderStyle.Width = Unit.Percentage(40);
    >
    > // create a label for the item template ...
    > label = new Label();
    > label.ID = "lbl" + Tree + "Location";
    > label.Text = "<%# DataBinder.Eval(Container.DataItem, 'Location') %>";
    >
    > // Add the label to the template column
    > ??? The unlike the dataGrid.Columns, the template column has no
    > Add method so how do I add the control ???
    >
    > dataGrid.Columns.Add(tc);
    >
    >
    > The area where the ??? are is where I need help. Any help would be

    appreciated.
    >
    > Thanks
    Rick Spiewak, Aug 7, 2004
    #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. Hai Nguyen
    Replies:
    0
    Views:
    402
    Hai Nguyen
    Jan 16, 2004
  2. Dexter
    Replies:
    1
    Views:
    418
    Eliyahu Goldin
    Jan 18, 2005
  3. Ken Varn
    Replies:
    1
    Views:
    975
    Ken Varn
    Aug 19, 2005
  4. herman404
    Replies:
    0
    Views:
    2,131
    herman404
    Jun 12, 2006
  5. =?Utf-8?B?Q2hyaXMgRmluaw==?=

    How to dynamically add control to datagrid item template

    =?Utf-8?B?Q2hyaXMgRmluaw==?=, Aug 20, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    582
    =?Utf-8?B?TWFuaXNoIEJhZm5h?=
    Aug 21, 2007
Loading...

Share This Page