0

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>
Twinkling Star
  • 135
  • 2
  • 14

1 Answers1

1

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

Community
  • 1
  • 1
Floremin
  • 3,969
  • 15
  • 20