Accessing a control (eg. Label) inside a datgrig

B

bredal Jensen

Hello there,

I need to show or hide a label cotrol in one of the cell of my datagrid.

I tried the following:


----------
DataGridItem item = MyDataGrid.Items[ MyDataGrid.EditItemIndex];

Label status= (Label) item.FindControl("MyGridStatus");



----------

But i get the following :

Object reference not set to an instance of an object.

when i do the following: status.Text = "My datagrid status"



I do this in the "update commande handler...



Can anyone help me with this issue?



Thanks in advance



Jensen
 
A

Ashish M Bhonkiya

the way you are trying to access is correct but the problem you are getting
that error is beac its not able to locate the label control.
try to debug. probably the label is not present or try to loop thru the
items in the datagrid.

HTH
Regards
Ashish M Bhonkiya
 
B

bredal Jensen

Right... I' d missed the runat="server" in the control definiton in my aspx
page.

Many thanks



Ashish M Bhonkiya said:
the way you are trying to access is correct but the problem you are getting
that error is beac its not able to locate the label control.
try to debug. probably the label is not present or try to loop thru the
items in the datagrid.

HTH
Regards
Ashish M Bhonkiya



bredal Jensen said:
Hello there,

I need to show or hide a label cotrol in one of the cell of my datagrid.

I tried the following:


----------
DataGridItem item = MyDataGrid.Items[ MyDataGrid.EditItemIndex];

Label status= (Label) item.FindControl("MyGridStatus");



----------

But i get the following :

Object reference not set to an instance of an object.

when i do the following: status.Text = "My datagrid status"



I do this in the "update commande handler...



Can anyone help me with this issue?



Thanks in advance



Jensen
 

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,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top