zoukankan      html  css  js  c++  java
  • 列表中数据的上下移动

    aspx页面代码:

    <%#(Convert.ToInt32(Eval("sortindex")) == nMaxIndex) ? "" : "<td class='wenzi'>
    <a href='#' onclick=\"sortInformation(" + Eval("fid") + "," + ",'up'," + Eval("sortindex") + ")\">上移</a></td>"%>
    
    <%#(Convert.ToInt32(Eval("sortindex")) == nMinIndex) ? "" : "<td class='wenzi'>
    <a href='#' onclick=\"sortInformation(" + Eval("fid") + "," + ",'down'," + Eval("sortindex") + ")\">下移</a></td>"%>

    上述三元表达式,保证当是列表中第一条数据时,没有上移链接,当是列表中最后一条数据时候,没有下移链接;

    aspx.cs文件代码:

    protected int nMaxIndex = FooterBLL.GetMaxIndex();  //获得最大索引
    protected int nMinIndex = FooterBLL.GetMinIndex();  //获得最小索引

      

    JS文件代码:

    //上下移动
    function sortInformation(keyID,optype,sortindex) {
        if (keyID <= 0) {
            alert("无效的信息ID参数,操作终止。");
            return;
        }
        if (sortindex <= 0) {
            alert("无效的索引值,操作终止。");
            return;
        }
        if (optype != ‘up’ && optype != 'down') {
            alert("无效的操作类型,操作终止。");
            return;
        }
    
        $.ajax({
            type: 'POST',
            url: 'UserControl/SetInfoSort.ashx',
            data: {
                KeyID: keyID,
                SortIndex: sortindex,
                OpType: optype
            },
            success: function (res) {
                if (res == 1) {
                    window.location.reload();
                } else {
                    alert("移动操作失败,请重试。");
                }
            },
            error: function () {
                alert("移动请求发送失败,请重试。");
            }
        });
    }

    ashx文件代码: 

    public class SetInfoSort : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
    
            string strRescult = "0";   //1:成功 0:失败
    
            string strKeyID = context.Request.Form["KeyID"];
            int nKeyID = 0;
            if (!int.TryParse(strKeyID, out nKeyID) || nKeyID <= 0)
            {
                context.Response.Write(strRescult);
                return;
            }
    
            string strSortIndex = context.Request.Form["SortIndex"];
            int nSortIndex = 0;
            if (!int.TryParse(strSortIndex, out nSortIndex) || nSortIndex <= 0)
            {
                context.Response.Write(strRescult);
                return;
            }
    
            string strCateID = context.Request.Form["CateID"];
            int nCateID = 0;
            if (!int.TryParse(strCateID, out nCateID) || nCateID <= 0)
            {
                context.Response.Write(strRescult);
                return;
            }
    
            string strOpType = context.Request.Form["OpType"];
         if(strOpType != "up" && strOpType != "down") { context.Response.Write(strRescult); return; } if (InformationBLL.SetInformationSort(nKeyID,nSortIndex,nOpType)) strRescult = "1"; context.Response.Write(strRescult); } public bool IsReusable { get { return false; } } }

    SQL存储过程:

    ALTER PROCEDURE [dbo].[Footer_Sort] 
        @UPKEYID    INT, --改变排序之前,序号较大者
        @DOWNKEYID  INT, --改变排序之前,序号较小者
    
        @RESCULT    INT OUTPUT   --1:成功 0:失败
    AS
    BEGIN
        SET @RESCULT = 0
    
        BEGIN TRAN T
            DECLARE @TEMPUP INT
            DECLARE @TEMPDOWN INT
            SELECT @TEMPUP = SORTINDEX FROM FOOTER WHERE FID = @UPKEYID
            SELECT @TEMPDOWN = SORTINDEX FROM FOOTER WHERE FID = @DOWNKEYID
    
            UPDATE FOOTER SET SORTINDEX = @TEMPDOWN WHERE FID = @UPKEYID
                IF(@@ERROR <> 0)
                BEGIN
                    ROLLBACK TRAN T
                END
    
            UPDATE FOOTER SET SORTINDEX = @TEMPUP WHERE FID = @DOWNKEYID
                IF(@@ERROR <> 0)
                BEGIN
                    ROLLBACK TRAN T
                END
            SET @RESCULT = 1
        COMMIT TRAN T
    
    END
  • 相关阅读:
    c# 图片保存为流Stream,再次加载时提示System.ArgumentOutOfRangeException: 要求非负数的解决办法
    VS 2019 Git failed with a fatal error的解决办法
    IIS安全狗卸载后,IIS8.5,网站无法访问的解决方法
    sqlserver 全文检索提高精确度的一个方法
    Win10应用商店打不开的解决办法
    Dapper解析嵌套的多层实体类
    Aspose.Words转换为PDF的时候字体丢失的问题解决
    IIS ASP.NET MVC 上传文件到NAS目录
    windows xp .net framework 4.0 HttpWebRequest 报The underlying connection was closed,基础连接已关闭
    c# 计算中文字节数与JAVA不符的解决方法
  • 原文地址:https://www.cnblogs.com/wxh19860528/p/2856526.html
Copyright © 2011-2022 走看看