我遇到LinkButton onclick事件没有触发的问题。
我查看了以下帖子并采取了Postback的预防措施,但仍然很高兴
repeater linkbutton not firing
Repeater's Item command event is not firing on linkbutton click
到目前为止,这是我的代码
<asp:PlaceHolder runat="server" ID="phOrders">
<asp:Repeater ID="rprOrders" runat="server" OnItemCommand="rprOrders_ItemCommand">
<HeaderTemplate>
<table>
<tr>
<th>
<asp:LinkButton ID="lnkOrderByDate" runat="server" Text="Date" CommandName="OrderDate" OnClick="lnkOrderByDate_Click"></asp:LinkButton></th>
<th>
<asp:LinkButton ID="lnkOrderByOrderNumber" runat="server" Text="Order Number"></asp:LinkButton></th>
<th>
<asp:LinkButton ID="lnkOrderByProductNumber" runat="server" Text="Product Number"></asp:LinkButton></th>
<th>Product Description</th>
<th>Size</th>
<th>QTY</th>
<th>Status</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><strong><%# Eval("OrderDate") %></strong></td>
<td><%# Eval("OrderNumber") %></td>
<td><%# Eval("SKUNumber") %></td>
<td><%# Eval("OrderItemSKUName") %></td>
<td><%# Eval("mtrx_Code2") %></td>
<td><%# Eval("OrderItemUnitCount") %></td>
<td><strong><%# Eval("OrderItemStatus") %></strong></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<div class="track-footer"></div>
</asp:PlaceHolder>
背后的代码
protected void SetupControl()
{
if (this.StopProcessing)
{
// Do not process
}
else
{
if (CMSContext.ViewMode == ViewModeEnum.LiveSite)
{
if(!Page.IsPostBack)
{
PopulateProductClass();
PopulateProduct();
PopulateDefaultViewOrders();
}
}
}
}
protected void lnkOrderByDate_Click(object sender, EventArgs e)
{
//Do Something
}
有什么建议吗?我似乎无法解决这个问题?
即使OnItemCommand="rprOrders_ItemCommand"
也不会开火?
答案 0 :(得分:3)
DataControl中的LinkButton
会触发方法rprOrders_ItemCommand
在那里设置一个断点。如果您有多个LinkButton
,那么您可以阅读CommandName="OrderDate"
Codebehind:(e.CommandName)
对于传递值,应使用CommandArgument
。
答案 1 :(得分:1)
使用像这样的东西
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" OnCommand="LinkButton1_Command" CommandName="MyUpdate" CommandArgument='<%# Eval("erid") %>'>LinkButton</asp:LinkButton>
</ItemTemplate>
protected void Repeater1_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("MyUpdate"))
{
// some code
}
if (e.CommandName.Equals("EditCategory"))
{
// some code
}
}