您好我有一个DataList页面:Asp.net访问DataList控件
<asp:DataList ID="DataList1" runat="server" BackColor="White" Width="98%" HorizontalAlign="Center" CellPadding="7" >
<ItemTemplate>
<uc1:ShopLine id="ShopLine1" runat="server" DataItem='<%# Container.DataItem %>'
ShopListLineId='<%# DataBinder.Eval(Container.DataItem, "ShopListLineID") %>'
OnDataUpdated="ShopLine1_DataUpdated">
</uc1:ShopLine>
</ItemTemplate>
<SeparatorStyle Width="1px" />
<ItemStyle CssClass="listItem1" />
</asp:DataList>
Shopline是一个ASCX文件。
我尝试使用下面的代码DataList控件来访问每个项目:
foreach (DataListItem dli in DataList1.Items)
{
string productId = DataBinder.Eval(dli.DataItem, "ProductID").ToString();
TextBox tb = (TextBox)dli.FindControl("QtyTextBox");
}
和dli.Dataitem是零和文本框为空为好,但在DataList acturally显示项目和shopline.ascs确实有一个TeXtBox ID是“QtyTextBox”。
任何人都可以给我一个主意吗?谢谢。
凡你有这样的代码? – Adil
你甚至可以放置这些代码?在检查dli.DataItem之前,通过使用快速手表来检查DataList1.Items中存在的项目和数量 –