0

我想订阅我页面上的 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 控件中正确订阅此事件?

4

2 回答 2

3

这有效:

<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
}
于 2009-01-22T01:38:49.247 回答
1

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

于 2008-09-30T01:29:16.050 回答