【问题标题】:AJAX.NET Subscribe to Reorderlist ItemCommand or DeleteCommand?AJAX.NET 订阅 Reorderlist ItemCommand 还是 DeleteCommand?
【发布时间】:2010-09-14 02:55:12
【问题描述】:

我想订阅我页面上的 Reorderlist 的 ItemCommand 事件。前端长这样……

<cc1:ReorderList id="ReorderList1" runat="server" CssClass="Sortables" Width="400"  OnItemReorder="ReorderList1_ItemReorder" OnItemCommand="ReorderList1_ItemCommand">
...
<asp:ImageButton ID="btnDelete" runat="server" ImageUrl="delete.jpg" CommandName="delete" CssClass="playClip" />
...
</cc1:ReorderList>

在后端我在 Page_Load 上有这个

ReorderList1.ItemCommand += new EventHandler<AjaxControlToolkit.ReorderListCommandEventArgs>(ReorderList1_ItemCommand);

并且定义了这个函数

protected void ReorderList1_ItemCommand(object sender, AjaxControlToolkit.ReorderListCommandEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            if (e.CommandName == "delete")
            {
                //do something here that deletes the list item
            }
        }
    }

尽管我尽了最大的努力,但我似乎无法让这个活动开始。如何在 ReorderList 控件中正确订阅此事件?

【问题讨论】:

    标签: c# asp.net events ajax.net reorderlist


    【解决方案1】:

    由于您的 ImageButton 是 CommandName="delete",您应该连接到 DeleteCommand 事件而不是 ItemCommand。

    【讨论】:

      【解决方案2】:

      这行得通:

      <cc2:ReorderList ID="rlEvents" runat="server" AllowReorder="True" CssClass="reorderList"
              DataKeyField="EventId" DataSourceID="odsEvents" PostBackOnReorder="False"
              SortOrderField="EventOrder" OnDeleteCommand="rlEvents_DeleteCommand">
      ...
      <asp:ImageButton ID="btnDeleteEvent" runat="server" CommandName="Delete" CommandArgument='<%# Eval("EventId") %>' ImageUrl="~/images/delete.gif" />
      ...
      </cc2:ReorderList>
      

      后面的代码:

      protected void rlEvents_DeleteCommand(object sender, AjaxControlToolkit.ReorderListCommandEventArgs e)
      {
         // delete the item
         // this will give you the DataKeyField for the current record -> int.Parse(e.CommandArgument.ToString());
         //rebind the ReorderList
      }
      

      【讨论】:

        猜你喜欢
        • 2010-09-12
        • 2021-01-24
        • 2021-10-16
        • 1970-01-01
        • 1970-01-01
        • 2021-10-24
        • 2019-08-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多