Repeater Linkbutton Onclick not firing

南笙酒味 提交于 2020-05-16 21:50:49

问题


I am having problem with the LinkButton onclick event not firing.

I have checked the following posts and taken the precaution of Postback but still joy

repeater linkbutton not firing

Repeater's Item command event is not firing on linkbutton click

Here is my Code so far

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

Code Behind

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
}

Any suggestions? I can't seem to figure it out?

Even the OnItemCommand="rprOrders_ItemCommand" wont fire either?


回答1:


use some thing like this

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



回答2:


The LinkButton within your DataControl triggers the Method rprOrders_ItemCommand

Set a breakpoint there. If you have multiple LinkButton then you can read CommandName="OrderDate" Codebehind: (e.CommandName)

For passing values CommandArgument should be used.



来源:https://stackoverflow.com/questions/36447366/repeater-linkbutton-onclick-not-firing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!