[英]Repeater ItemCommand Doesnt fire
我已经尝试过发布同一主题的帖子,但是没有用。 它实际上并没有触发事件
我想要的是
我想在某些点击中继器时触发ItemCommand
事件。
问题
未触发ItemCommand
。
EnableViewState=true
这是通过代码:
HTML:
<table>
<asp:Repeater ID="outerRepeater" runat="server"
OnItemDataBound="outer_OnitemdataBound"
onitemcommand="outerRepeater_ItemCommand">
<ItemTemplate>
<asp:Repeater ID="Rgallery" runat="server">
<ItemTemplate>
<%# (Container.ItemIndex + 4) % 4 == 0 ? "<tr>" : string.Empty %>
<td>
<img src="<%# Eval("ImgPath") %>" style="height:300px; width:300px;" alt="" />
<div class="caption">
<h3><%# Eval("Type") %></h3>
<p><b><%# Eval("SubType") %></b></p>
<p{font-family: "Comic Sans MS", cursive, sans-serif; font-size: 25px}>Price:<i class="fa fa-inr fa-fw"><%# Eval("Price") %></i></p>
<p><asp:Button ID="btnBuy" CommandName="Buy" CommandArgument="Add to Cart" class="btn btn-primary" Text='<%# DataBinder.Eval(Container.DataItem, "Price") %>' runat="server" />
</p>
</div>
</td>
<%# (Container.ItemIndex + 4) % 4 == 3 ? "</tr>" : string.Empty%>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
<asp:Label ID="lblStatus" runat="server" ></asp:Label>
</table>
这是背后的代码
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dummy = new DataTable();
dummy.Columns.Add();
dummy.Rows.Add();
rptMain.DataSource = dummy;
rptMain.DataBind();
outerRepeater.DataSource = dummy;
outerRepeater.DataBind();
}
if (Page.IsPostBack)
{ return; }
}
protected void outerRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
// Here is a code I want to fire
}
protected void outer_OnitemdataBound(object sender, RepeaterItemEventArgs e)
{
Repeater repeater = e.Item.FindControl("RGallery") as Repeater;
repeater.DataSource = db.GetTable("SELECT `Did`, `Type`, `SubType`, `Gender`, `Price`, `ImgPath` FROM `designs` ORDER BY `Did` DESC");
repeater.DataBind();
}
到目前为止我尝试过的
方法1
我放了onItemCommand="rptthumbnail_ItemCommand"
但是我没有工作。
方法2我在OnInit()
添加了handlar,但是我也没有工作。
可以请一些人找出问题所在吗.....
由于您的按钮是内部中继器的子级,因此它将触发该事件上的ItemCommand
事件。 将事件绑定向下移动到该转发器应该可以为您解决。
<asp:Repeater ID="outerRepeater" runat="server"
OnItemDataBound="outer_OnitemdataBound">
<ItemTemplate>
<asp:Repeater ID="Rgallery" runat="server"
OnItemCommand="Rgallery_ItemCommand">
protected void Rgallery_ItemCommand(object source, RepeaterCommandEventArgs e)
{
// Here is a code I want to fire
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.