I have a repeater with some labels, they all work fine except the last one leading to NullReferenceException. Probably there is a banal sintax mistake... but i can't see it!
<asp:Repeater ID="ticketrep1" runat="server" OnItemDataBound="TicketsRep_ItemDataBound">
<ItemTemplate>
<asp:Label runat="server" ID="tksubject" Style="font-weight:bold;" />
<asp:Label runat="server" ID="breadctrail" Style="font-weight:bold;" />
</ItemTemplate>
</asp:Repeater>
Code Behind:
protected void TicketsRep_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label tksubject = (Label)e.Item.FindControl("tksubject");
tksubject.ClientIDMode = ClientIDMode.Static;
tksubject.ID = "tksubject" + Ticket.idTicket;
tksubject.Text = Ticket.oggetto;
Label breadctrail = (Label)e.Item.FindControl("breadctrail");
breadctrail.ClientIDMode = ClientIDMode.Static;
breadctrail.ID = "breadcrumbtrail" + Ticket.idTicket;
breadctrail.Text = Ticket.categoria.ToString();
}
}
NullReferenceException appears in the first line after declaration: breadctrail.ClientIDMode = ClientIDMode.Static;
so I tried to comment it and the error simply pass to the second line. breadctrail appears Null.
Thank you all.
Edit for "possible duplicate": Of two (and more) labels with apparently the same syntax, only one gives an error. Why?
Thank you again.