中继器链接按钮 Onclick 未触发

Repeater Linkbutton Onclick not firing

我遇到了 LinkBut​​ton onclick 事件未触发的问题。

我已经检查了以下帖子并采取了回传的预防措施,但仍然很高兴

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"也不会开火?

DataControl 中的 LinkButton 触发方法 rprOrders_ItemCommand

在那里设置一个断点。如果你有多个 LinkButton 那么你可以阅读 CommandName="OrderDate" 代码隐藏:(e.CommandName)

要传递值,应使用 CommandArgument

使用这样的东西

<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>

.cs

    protected void Repeater1_OnItemCommand(object source, RepeaterCommandEventArgs e)
 {
    if (e.CommandName.Equals("MyUpdate"))
    {
        // some code
    }

    if (e.CommandName.Equals("EditCategory"))
    {
        // some code
    }
}