easyui datagrid实现单行的上移下移,以及保存移动的结果

    开始接触easyui感觉他的封装真是极佳的,善假于物的思想使我们善于站在巨人的肩膀上,人家封装好这么好的插件直接让俺们使用,我们在需求不同可进行简单的调整。 

</span>//调整展示次序加载图片
    function UpDownFormat(value, row, index) {
        //只有向下的按钮
        var data = $('#Convention').datagrid('getData');
        
        if (index == 0) {
            return "<a href=\"javascript:Down(" + index + ")\"><img src=\"../../Content/jquery-easyui-1.3.2/themes/icons/accordion_arrows_down.png\" /></a>"
        } else if (index == data.total-1) {
            return "<a href=\"javascript:Up(" + index + ")\"><img src=\"../../Content/jquery-easyui-1.3.2/themes/icons/accordion_arrow_up.png\" /></a>"
        } else {
            return "<a href=\"javascript:Up(" + index + ")\"><img src=\"../../Content/jquery-easyui-1.3.2/themes/icons/accordion_arrow_up.png\" /></a>  <a href=\"javascript:Down(" + index + ")\"><img src=\"../../Content/jquery-easyui-1.3.2/themes/icons/accordion_arrows_down.png\" /></a>"
        }
        
    }
 <pre name="code" class="javascript"> //点击进入界面时加载数据
<pre name="code" class="javascript">$(document).ready(function () {

    var strConvention = "";
    //加载公约表格
    $('#Convention').datagrid({
        url: '/FreshConfiguration/QueryConvention?strConvention=' + strConvention,

        rownumbers: "true",
        title: "公约配置信息",
        loadMsg: '正在加载公约信息...',
        singleSelect: true,

        columns: [[
    { field: 'ck', checkbox: true, align: 'left', width: 60, align: "center" },

    {field: 'ConventionName', title: '公约名称', width: 385, align: "center", formatter: titleFormat},
    { field: 'isuse', title: '是否启用', width: 385, align: "center" },
    //{ field: 'ConventionContent', title: '公约内容', width: 290, align: "center" },
    { field: 'Adjust', title: '优先级次序', align: 'center', width: 383, formatter: UpDownFormat }//点击按钮进行上下行的数据交换
        ]],

        toolbar: [{
            id: 'btnAdd',
            text: '添加',
            iconCls: 'icon-add',
            handler: function () {
                window.location.href = "/FreshConfiguration/AddConventionConfigView"
                //showAddCon();
            }
        }, '-', {
            id: 'btnDelete',
            text: '删除',
            iconCls: 'icon-remove',
            handler: function () {
                doDelete();
            }

        }, '-', {
            id: 'btnUse',
            text: '<input type="radio" name="radio">启用</input>',
            handler: function () {
                doUse();
            }
        }, {
            id: 'btnDelete',
            text: '<input type="radio" name="radio"> 不启用</input>',
            handler: function () {
                doDisable();
            }

        }
        ],
        onHeaderContextMenu: function (e, field) {
        },
        onLoadSuccess: function (data) {
            $(".delUser").unbind("click");
            $(".delUser").bind("click", function () {
                alert($(this).attr("uid"));
                return false;
            });

            $(".editUser").unbind("click");
            $(".editUser").bind("click", function () {
                doEdit($(this).attr("uid"));
                return false;
            });
        }

    });
})
<script>    //调整编码次序

    function Up(index) {
        //向下移动改变的地index行和index+1行
        $('#Convention').datagrid('selectRow', index)
        var row = $('#Convention').datagrid('getSelected');
        $.ajax({
            type: "POST",
            url: "/FreshConfiguration/UpdateSortConvention",
            data: "ConventionID=" + row.ConventionID + "&conventionSort=" + index,
            success: function () {//成功之后
                $('#Convention').datagrid('selectRow', index - 1);
                var row1 = $('#Convention').datagrid('getSelected')
                $.ajax({
                    type: "POST",
                    url: "/FreshConfiguration/UpdateSortConvention",
                    data: "ConventionID=" + row1.ConventionID + "&conventionSort=" + (index + 1),
                    success: function () {//提示信息
                        // $.messager.alert("提示!", "编码次序调整成功!");
                        $("#Convention").datagrid("reload");
                        $('#Convention').datagrid('showColumn', 'Adjust');
                    },
                    error: function () {
                        $.messager.alert("警告!", "编码次序调整失败,请联系管理员!", "info");
                    }
                });
            },
            error: function () {
                $.messager.alert("警告!", "编码次序调整失败,请联系管理员!", "info");
            }
        });
    }

    function Down(index) {
        //向下移动改变的地index行和index+1行
        $('#Convention').datagrid('selectRow', index)
        var row = $('#Convention').datagrid('getSelected');
        $.ajax({
            type: "POST",
            url: "/FreshConfiguration/UpdateSortConvention",
            data: "ConventionID=" + row.ConventionID + "&conventionSort=" + index + 2,
            success: function () {//成功之后
                $('#Convention').datagrid('selectRow', index + 1);

                var row1 = $('#Convention').datagrid('getSelected')
                $.ajax({
                    type: "POST",
                    url: "/FreshConfiguration/UpdateSortConvention",
                    data: "ConventionID=" + row1.ConventionID + "&conventionSort=" + (index + 1),
                    success: function () {//提示信息
                        // $.messager.alert("提示!", "编码次序调整成功!");
                        $("#Convention").datagrid("reload");
                        $('#Convention').datagrid('showColumn', 'Adjust');
                    },
                    error: function () {
                        $.messager.alert("警告!", "编码次序调整失败,请联系管理员!", "info");
                    }
                });
            },
            error: function () {
                $.messager.alert("警告!", "编码次序调整失败,请联系管理员!", "info");
            }
        });
    }

</script>
<span style="font-size:24px;">   以上是js的有关代码,前台界面的有关代码已经放到上面。</span>
<span style="font-size:24px;">
</span>
<span style="font-size:24px;">   存储到数据库需要调用controller的更新方法UpdateSortConvention,</span>
<span style="font-size:24px;"></span><pre name="code" class="javascript">#region 公约配置界面更新公约功能-赵尽朝-2016-8-24 16:37:32
        [ValidateInput(false)]
        [HttpPost]
        public void UpdateSortConvention(string ConventionContent, string ConventionName, string IsUse, string conventionSort, string ConventionID)
        {
            ConventionViewModel convention = new ConventionViewModel();
            convention.ConventionID = ConventionID;

            string str = "TimeSpan";

            if (conventionSort != null && conventionSort != "")
            {
                str += ",conventionSort";
                convention.conventionSort = int.Parse(conventionSort);
            }

            //内容
            if (ConventionContent != null && ConventionContent != "")
            {
                str += ",ConventionContent";
                convention.ConventionContent = ConventionContent;
            }
            //标题
            if (ConventionName != null && ConventionName != "")
            {
                str += ",ConventionName";
                convention.ConventionName = ConventionName;
            }

            //展示顺数
            if (IsUse != null && IsUse != "")
            {
                str += ",IsUse";
                convention.IsUse = int.Parse(IsUse);
            }

            //数组
            string[] strarray = str.Split(',');
            //调用后台方法
            conventionBll.UpdateSortConvention(convention, strarray);

        }
        #endregion

IBll层:
     bool UpdateSortConvention(ConventionViewModel StuConvention, string[] str);
Bll层:
<span style="font-size:24px;"></span><pre name="code" class="csharp">#region 修改公约信息 UpdateSortConvention 赵尽朝2016-07-31
        public bool UpdateSortConvention(ConventionViewModel StuConvention, string[] str)
        {
            //实例化公约信息,并把viewmodel赋值给实体的属性
            freshconventionentity Conventioninfo = new freshconventionentity
            {  //更新整张表,给字段赋值 
                ConventionID = StuConvention.ConventionID, 
                ConventionName = StuConvention.ConventionName,
                ConventionContent = StuConvention.ConventionContent,
                IsUse = (StuConvention.isuse=="是")?1:0,
                conventionSort = StuConvention.conventionSort,
                ConventionTimestamp= DateTime.Now,
                isDelete = 0
            };
            this.ConventionCurrentDal.Update(Conventioninfo, q => q.ConventionID == StuConvention.ConventionID,str);
            //完成实务操作
            bool result = DbSession.SaveChanges() > 0;
            return result;
        }


    
遇到的错误: 


一、检测到有潜在危险的 Request.Form 值

    这种问题是因为你提交的Form中有HTML字符串,例如你在TextBox中输入了html标签,或者在页面中使用了HtmlEditor组件等,解决办法是禁用validateRequest。

    如果你是.net 4.0或更高版本,一定要看方法3。此方法在asp.net webForm和MVC中均适用

方法1
在.aspx文件头中加入这句:<%@ Page validateRequest="false"  %>

方法2
修改web.config文件:
<configuration>
    <system.web>
        <pages validateRequest="false" />
    </system.web>
</configuration>

因为validateRequest默认值为true。只要设为false即可。

方法3:
web.config里面加上

<system.web>
    <httpRuntime requestValidationMode="2.0" />
</system.web>

    因为4.0的验证在HTTP的BeginRequest前启用,因此,请求的验证适用于所有ASP.NET资源,aspx页面,ashx页面,Web服务和一些HTTP处理程序等.


二、对一个或多个实体的验证失败。有关详细信息,请参见“EntityValidationErrors”属性        

   问题原因:(问题ef都是相同错误提示
       1. 非空列未插入值错误
       2. 多个表间外键列长度不一样
       3. ef上下文对象db为空 
       4. ef上下文设置属性为 db.Configuration.ValidateOnSaveEnabled = false;
       5. 内容长度超过列最大长度

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 35
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 35
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值