Question : Find Label in Datalist within Gridview

Hi,

I am having difficulty in finding a label control from the codebehind.
The label I am trying to find is within a datalist which is within a gridview row.

I can find the label if I place within the Gridview using  Label ReviewTextLabel = (Label)e.Row.FindControl("ReviewTextLabel");

 but cannot seem to find when I place within the datalist, this is within CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)

Thanks

C

Answer : Find Label in Datalist within Gridview

You have ReviewTextLabe for each item in DataList correct?
If so then do that finding label inside DataList ItemDataBound event like:

 protected void ReviewDataList_ItemDataBound(object sender, DataListItemEventArgs e)
    {
      Label ReviewTextLabel = (Label)e.Item.FindControl("ReviewTextLabel");
        if (ReviewTextLabel != null)
        {
           //Do your work with ReviewTextLabel
        }
}
Random Solutions  
 
programming4us programming4us