从列表视图访问标签控件

问题描述:

我无法从列表视图访问标签。 我一直在阅读所有帖子,但似乎没有任何工作。 这是我的代码。从列表视图访问标签控件

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> 

LayoutTemplate中的标签控制,因此它不是任何ListView项目的一部分。尽量只:

ListView.FindControl("nItemsId") 

你有什么,如果标签是的ItemTemplate

更多关于这个话题在这里部分将工作:Access a control inside a the LayoutTemplate of a ListView

+0

感谢。有效。 – 2013-04-04 18:08:11