Accessing a control (eg. Label) inside a datgrig

  • Thread starter Thread starter bredal Jensen
  • Start date Start date
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
 
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
 
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
 
Back
Top