EasyUI使用DataGrid向服务器传参

由于DataGrid自带有Post方式,使用Url可以向指定的地址Post数据,所以从这方面来看和Jquery的Ajax非常像(我想应该就是使用的Ajax,不过没有深入研究过Easyui的源代码)。但是区别于Ajax,DataGrid的参数不是使用Data属性(Data属性中的数据是显示在表格中的),而是使用QueryParams这个属性。

简单举个例子,从A页面点击某个链接跳转到B页面,从B页面显示A中链接内容的详细信息。这里就要求在A页面中点击链接时需要将可以查询的主键传递过来。从而在B页面刷新时在服务器端根据该主键进行查询。JS示例代码如下:

$('#tb').datagrid({
                url: 'Data/设备情况明细表.aspx',
                width: '100%',
                fitColumns: true,
                showFooter: true,
                singleSelect: true,//只允许选择一行
                loadMsg: "正在努力加载,请稍等。",
                queryParams: id: getParameter("id"),
                columns: [[
                    { field: '_id', title: '行号', fixed: true },
                    { field: '_j', title: '铁路局', fixed: true },
                    { field: '_name', title: '测点名称', fixed: true }
                ]]
});

在 设备情况明细表.aspx 页面中 C#代码示例如下:

public string id
        {
            get
            {
                if (Request["id"] != null && Request["id"].ToString() != "")
                {
                    return Request["id"].ToString();
                }
                else
                {
                    return "";
                }
            }
        }

这样在服务器中就可以获取到前台传递过来的参数内容。

posted @ 2014-10-27 20:10  占星师  阅读(2836)  评论(0编辑  收藏  举报