Asp.net 如何在页面回发后循环中继器数据项
我在中继器中有一个按钮,我想在这个按钮点击事件中循环中继器的数据项。这是我的密码:Asp.net 如何在页面回发后循环中继器数据项,asp.net,c#-4.0,repeater,Asp.net,C# 4.0,Repeater,我在中继器中有一个按钮,我想在这个按钮点击事件中循环中继器的数据项。这是我的密码: protected void btnPromotionButton_OnClick(object sender, EventArgs e) { try { foreach (RepeaterItem item in rptPromotionProducts.Items) { if (item.
protected void btnPromotionButton_OnClick(object sender, EventArgs e)
{
try
{
foreach (RepeaterItem item in rptPromotionProducts.Items)
{
if (item.DataItem == null)
{
continue;
}...
这是我的中继器:
<asp:Repeater ID="rptPromotionProducts" runat="server" OnItemDataBound="rptPromotionProducts_OnItemDataBound">
<ItemTemplate>
<li>
<asp:HyperLink runat="server" ID="hlProduct" CssClass="product_image">
<asp:Image runat="server" ID="imgWindow" />
</asp:HyperLink>
<div class="product_info">
<h3>
<a href="#">
<%# Eval("Name") %></a></h3>
</div>
<div>
<asp:Button ID="btnPromotionButton" runat="server" Text="Sepete Ekle" OnClick="btnPromotionButton_OnClick" />
</div>
</div>
</li>
</ItemTemplate>
</asp:Repeater>
item.DataItem始终为空,但中继器有行。这是否可能在页面发布后循环并返回 类似的问题已经得到了回答 这个问题的简短答案是“否”。回发后您无法访问数据项
检索数据的替代方法是使用隐藏字段、链接到中继器的数据源或包含数据的会话对象。您试图为每一行获取什么?您是否试图找出单击了哪一行?尽管他可以循环并获取中继器中每个控件的值(如
item.FindControl(“hlProduct”)
)。所以我想说,答案是肯定的,只是换一种方式。但如果能知道他想要实现什么,那就太好了。