Reputation: 37
I have a variable "mininum" that needs to be assigned to a label "minLabel", his label is inside a template view which is inside a gridview. When try minLabel.text= mininum it I get the error that the label does not exist. How do I reference the label so that I can assign the variable to it?
Thanks
studentGrid.Parent.FindControl("minLabel")
minLabel.Text = minObject
<asp:TemplateField HeaderText="Class min">
<ItemTemplate>
<asp:Label ID="minLabel" runat="server" Text="Label"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Upvotes: 1
Views: 3145
Reputation: 5636
You cannot assign a value of a control placed inside grid view like you mentioned
minLabel.text= mininum
This is the way to find control inside gridview...
protected void studentGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
(Label)e.Row.FindControl("minLabel").Text = "mininum";
}
}
Hope it works for you.
Upvotes: 1
Reputation: 13960
You need to get a reference to the label first. Use:
myGrid.Parent.FindControl("minLabel");
Then, proceed as usual.
Upvotes: 0