Using labels in the HeaderTemplate of a datagrid or datalist

R

ree32

when I try to access this label to place a text in it in the code. I
get this error -
Object reference not set to an instance of an object.


I assume this because the label is within the datalist I can't get a
control of it.

Is there anyway around this?
 
R

ree32

I need to use a label as the Text dynamically changes. As this
datagrid/list is in a usercountrol. Different headings will be fed
into the user control.
 
M

Michael Tkachev

You can use the following code:

datagrid.Columns[0].HeaderText = "bla-bla";
 
R

ree32

Michael Tkachev said:
You can use the following code:

datagrid.Columns[0].HeaderText = "bla-bla";

You have it wrong this is not the header of the column but the header
of the whole datagrid/datalist.
 
G

Gary K

Then why is the text in a headertemplate? Anyways, to change any control in a
template column you need to use the FindControls method. For events you can
get away with something like, e.Item.FindControl("ctrlid"). It returns a
general object so you will need to typecast it. Outside events I'd use
grid.Rows.FindControl("ctrlid").

ree32 said:
Michael Tkachev said:
You can use the following code:

datagrid.Columns[0].HeaderText = "bla-bla";

You have it wrong this is not the header of the column but the header
of the whole datagrid/datalist.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top