AJAX.NET 订阅Reorderlist ItemCommand 或DeleteCommand?

发布于 2024-07-06 04:57:41 字数 1064 浏览 8 评论 0原文

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

I would like to subscribe to the ItemCommand event of a Reorderlist I have on my page. The front end looks like this...

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

in the back-end I have this on Page_Load

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

and this function defined

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

Despite my best efforts though, I can't seem to get this event to fire off. How do you properly subscribe to this events in a ReorderList control?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

避讳 2024-07-13 04:57:41

这有效:

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

this works:

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

code behind:

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
}
眼泪淡了忧伤 2024-07-13 04:57:41

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

Since your ImageButton's CommandName="delete" you should be hooking up to the DeleteCommand event instead of ItemCommand.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文