中继器 ItemCommand 不触发
Repeater ItemCommand Doesnt fire
我已经尝试 post 同一主题,但没有成功。它实际上并没有触发事件
What I want
我要开火
ItemCommand
当有人点击转发器时的事件。
Issue
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();
}
What i have tried so far
方法一
我放了onItemCommand="rptthumbnail_ItemCommand"
但是没成功
方法二
我在 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
}
我已经尝试 post 同一主题,但没有成功。它实际上并没有触发事件
What I want
我要开火
ItemCommand
当有人点击转发器时的事件。
Issue
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();
}
What i have tried so far
方法一
我放了onItemCommand="rptthumbnail_ItemCommand"
但是没成功
方法二
我在 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
}