Using labels within datagrid template headings

  • Thread starter Thread starter John
  • Start date Start date
J

John

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,

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

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.
 

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

Back
Top