[英]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.