我试过关于同一主题的帖子,但没有成功。它实际上并没有发生火灾事件
我想要的
我想触发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()中添加了手,但我没有工作。
能不能请一些人找出问题所在,请帮我解决这个问题……
发布于 2015-11-28 20:01:44
因为您的按钮是内部中继器的子级,因此它将触发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
}https://stackoverflow.com/questions/33975200
复制相似问题