Using labels within datagrid template headings

Discussion in 'ASP .Net' started by John, Apr 10, 2005.

  1. John

    John Guest

    Hi all,

    Am I allowed to use labe;s within the datagrid heading section? Each time I
    drag a label onto the design, I can set the properties and such (including
    runat=server) but the code-behind refuses to accept/acknowledge it's
    existence.

    Am I just doing something wrong and if so, what?

    Regards
    John.
    John, Apr 10, 2005
    #1
    1. Advertising

  2. John,

    If you want to programatically access a control which is part of a DataGrid, you need to handle it in the ItemDataBound event.

    your code will look something like this in the ItemDataBound event handler:

    if(e.ItemType == ListItemType.Item || e.ItemType == ListItemType.AlternateItem)
    {
    Label lbl = (Label)e.Item.FindControl("controlName");
    lbl.Text = "Hello World";
    }

    Hope this helps.

    "John" <> wrote in message news:...
    > Hi all,
    >
    > Am I allowed to use labe;s within the datagrid heading section? Each time I
    > drag a label onto the design, I can set the properties and such (including
    > runat=server) but the code-behind refuses to accept/acknowledge it's
    > existence.
    >
    > Am I just doing something wrong and if so, what?
    >
    > Regards
    > John.
    >
    >
    Steven Berkovitz, Apr 10, 2005
    #2
    1. Advertising

  3. John

    John Guest

    Man oh man . . .

    It worked - THANKS

    I understand how that would work - I already have quite a bit of items I'm
    binding to within the ItemDataBound sub but didn't realize that for headers,
    it fires up once so I can set them up.

    Again, thanks.

    Regards
    John.

    "Steven Berkovitz" <> wrote in message
    news:...
    John,

    If you want to programatically access a control which is part of a DataGrid,
    you need to handle it in the ItemDataBound event.

    your code will look something like this in the ItemDataBound event handler:

    if(e.ItemType == ListItemType.Item || e.ItemType ==
    ListItemType.AlternateItem)
    {
    Label lbl = (Label)e.Item.FindControl("controlName");
    lbl.Text = "Hello World";
    }

    Hope this helps.

    "John" <> wrote in message
    news:...
    > Hi all,
    >
    > Am I allowed to use labe;s within the datagrid heading section? Each time
    > I
    > drag a label onto the design, I can set the properties and such (including
    > runat=server) but the code-behind refuses to accept/acknowledge it's
    > existence.
    >
    > Am I just doing something wrong and if so, what?
    >
    > Regards
    > John.
    >
    >
    John, Apr 10, 2005
    #3
    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. Saravana

    Re: Datagrid headings

    Saravana, Jul 22, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    440
    Saravana
    Jul 23, 2003
  2. Tracey
    Replies:
    0
    Views:
    363
    Tracey
    Jul 23, 2003
  3. =?Utf-8?B?QWxhbiBMYW1iZXJ0?=

    Headings in the DataGrid Web Control

    =?Utf-8?B?QWxhbiBMYW1iZXJ0?=, Sep 29, 2004, in forum: ASP .Net
    Replies:
    10
    Views:
    730
    =?Utf-8?B?Y29vbHRlY2g3Nw==?=
    Mar 5, 2006
  4. Bazza Formez
    Replies:
    2
    Views:
    379
    Bazza Formez
    Dec 8, 2004
  5. tshad

    Change DataGrid Headings color

    tshad, Jun 9, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    3,695
    Winista
    Jun 14, 2006
Loading...

Share This Page