I want to take the Label control with ID TextLabel
in the code behind, but this give me the following exception Object reference not set to an instance of an object.
The exception is on this line of code in code behind file:
Label label = e.Item.FindControl("TextLabel") as Label;
string text = label.Text;
What mistake I made here ? How to find "TextLabel" control in code behind ?
aspx code:
<asp:Repeater ID="UserPostRepeater" runat="server" OnItemDataBound="UserPostRepeater_ItemDataBound">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="TextLabel" runat="server" Text="Label"></asp:Label>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
code-behind:
protected void UserPostRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
BlogProfileEntities blogProfile = new BlogProfileEntities();
Label label = e.Item.FindControl("TextLabel") as Label;
string text = label.Text;
}