AJAX.NET订阅Reorderlist ItemCommand还是DeleteCommand?

时间:2008-09-29 21:09:33

标签: c# asp.net events ajax.net 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控件中正确订阅此事件?

2 个答案:

答案 0 :(得分: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
}

答案 1 :(得分:1)

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