Reputation: 135
I unable to access label from listview. I have been reading all posts, but nothing seems to work. Here is my code.
for (int i = 0; i < ListView1.Items.Count; i++)
{
Label someLabel = (Label) ListView1.Items[i].FindControl("nItemsId");
if (someLabel != null)
someLabel.Text = "100";
}
<asp:ListView runat="server" ID="ListView1" DataKeyNames="ProductId" DataSourceID="GameTable" OnItemCommand="On_Select_Item" >
<LayoutTemplate>
<table runat="server" id="gametable" cellspacing="0" cellpadding="1" border="0">
<tr style="height: 20px; font-size: 20px; color: Red">
<th>
<asp:Label runat="server" Text="5" ID="nItemsId" cssClass="cart">
</asp:Label>
</th>
</tr>
......................................
------------------------------
</asp.ListView>
Upvotes: 0
Views: 1109
Reputation: 4089
Label control inside the LayoutTemplate so it's not part of any ListView
item. Try just:
ListView.FindControl("nItemsId")
What you have would work if the label was part of ItemTemplate
More on this topic here: Access a control inside a the LayoutTemplate of a ListView
Upvotes: 1