weixin_33698823 2010-09-29 13:44 采纳率: 0%
浏览 31

Ajax重新排序列表不可拖动

I have the same problem as Simon in this post.

He found out some sort of a solution, but it does not work for me. Please, could someone explain me what is going on in this answer or advice me something else.

PS: there is an example on the asp.net site which doesn't work exactly the same way as my reorder list... (click view a demo)

The solution that is suggested here adds these few lines to web.config:

<httpHandlers> 

  <add path="ScriptResource.axd" verb="GET,HEAD" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/> 

</httpHandlers> 

Perhaps I just need to change something to make it work... but I don't know what. For example I have no idea what the ScriptResource.axd is supposed to be.

My code: .aspx file

    <%@ Page Title="" Language="C#" MasterPageFile="~/editor/editor_template.Master" AutoEventWireup="true" CodeBehind="menuEditor.aspx.cs" Inherits="WebPageEditor.editor.menuEditor" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
</asp:ScriptManager>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>

     <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
            DeleteMethod="DeleteMenu" InsertMethod="InsertMenu" SelectMethod="SelectMenu" 
            TypeName="WebPageEditor.editor.MenuSourceManager" UpdateMethod="UpdateMenu"
             >
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="name" Type="String" />
                <asp:Parameter Name="url" Type="String" />
                <asp:Parameter Name="order" Type="Int32" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="ID" Type="Int32" />
                <asp:Parameter Name="name" Type="String" />
                <asp:Parameter Name="url" Type="String" />
                <asp:Parameter Name="order" Type="Int32" />
            </UpdateParameters>            
        </asp:ObjectDataSource>

        <asp:ReorderList ID="ReorderList1" runat="server" AllowReorder="True" 
            DataSourceID="ObjectDataSource1" PostBackOnReorder="False" 
            ShowInsertItem="True"       SortOrderField="order" DataKeyField="ID" 
            ItemInsertLocation="Beginning">

            <ItemTemplate>
            <div class="menuEditor">
            &raquo;   <%# Eval("name") %>  
            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit">LinkButton</asp:LinkButton>
            </div>               
            </ItemTemplate>

            <DragHandleTemplate>
                <img src="ico/moveHandle_ico.gif" 
                alt='<asp:Literal ID="Literal1" runat="server" Text="<%$ Resources: editorLocalization, ME_moveHandleTT %>" />'
                style="cursor:move; width:35px;" />
            </DragHandleTemplate>
            <ReorderTemplate>
            <asp:Panel runat="server" />

            </ReorderTemplate>

            <InsertItemTemplate>
                <asp:Panel ID="panel1" runat="server" DefaultButton="Button1">
                                  <asp:TextBox ID="TextBox1" runat="server" Text=' <%# Bind("name") %>' ValidationGroup="add" />
                                    <asp:Button ID="Button1" runat="server" CommandName="Insert" Text="Add"  ValidationGroup="add" />
                                   <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ValidationGroup="add"
                                        ErrorMessage="Please enter some text" ControlToValidate="TextBox1" />
                                </asp:Panel>
            </InsertItemTemplate>

            <EditItemTemplate>
            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("name") %>' ValidationGroup="edit" />
                <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("url") %>' ValidationGroup="edit" />
                     <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("order") %>' ValidationGroup="edit" />
                  <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update">LinkButton</asp:LinkButton>

            </EditItemTemplate>

        </asp:ReorderList>        



    </ContentTemplate>
    </asp:UpdatePanel>




</asp:Content>

and the code behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace WebPageEditor.editor
{

    public class MenuSourceManager 
    {
        public static List<MenuItem> menuItems;  

        #region DataBindMethods
        //[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select)]
        public List<MenuItem> SelectMenu()
        {            
            return menuItems;  
        }

        public void UpdateMenu(int ID, string name, string url, int order)
        {
            menuItems[ID].Name = name;
            menuItems[ID].Url = url;
            menuItems[ID].Order = order;            
        }

        public void InsertMenu(string name, string url, int order)
        {
            menuItems.Add(new MenuItem(name, url, order, menuItems.Count));
        }

        public void DeleteMenu(int ID)
        {
            menuItems.RemoveAt(ID);
        } 
        #endregion  
    }

    public class MenuItem
    {
        public MenuItem(string name, string url, int order, int ID)
        {
            Name = name; Url = url; Order = order; this.ID = ID;
        }

        public string Name { get; set; }
        public string Url { get; set; }
        public int Order { get; set; }
        public int ID { get; set; }
    }
}

I load the data to the List collection from the page_load event but that works fine. The data binding works as well. The problem is in that the items cannot be reordered -- during the reordering, the sort value doesn't change and the list doesn't update.

  • 写回答

2条回答 默认 最新

  • weixin_33743703 2010-10-08 14:21
    关注

    Add this event with your reorder list tag

    OnItemReorder="ReorderList1_ItemReorder"
    

    Now on code behind add this code:

    protected void ReorderList1_ItemReorder(object sender, AjaxControlToolkit.ReorderListItemReorderEventArgs e)
            {
    //write your logic here to sort order change.
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常