【问题标题】:How to Bind the JQGrid Dynamically如何动态绑定 JQGrid
【发布时间】:2012-03-13 06:36:45
【问题描述】:

我是 JQGrid 和 JQUery 的新手,请给我解决方案?

我正在使用 JQGrid 开发 Sharepoint application2010,我想在 JQGrid 中显示列表数据。为此,我有数据集,使用我需要绑定 JQGrid 的数据集,该数据集具有不同的列。

当我们使用 Noraml asp.net Gridview 时,我们可以像下面一样直接提供数据源,无需提及列,就像我需要开发 JQGrid 一样。

<asp:Gridview runat="server" id="GvSample"/>

在.cs中

GVSample.datasource=ds;
gvSample.databind();

请帮忙!

【问题讨论】:

  • 您的问题找到解决方案了吗?

标签: asp.net sharepoint jqgrid


【解决方案1】:

您可以在此处查看 asp.net 中的 JQGrid 示例。它展示了如何将数据源和列绑定到 JQGrid。

http://www.trirand.net/demoaspnet.aspx

【讨论】:

  • 其实我的要求是,我不能设置数据字段,因为列是动态变化的。
【解决方案2】:

先获取列的详细信息,然后绑定。

把这个放到document.ready中

$.ajax(
    {
       type: "POST",
       url: "SomeUrl/GetColumnsAndData",
       data: "",
       dataType: "json",
       success: function(result)
       {
            colD = result.colData;
            colN = result.colNames;
            colM = result.colModel;

            jQuery("#list").jqGrid({
                jsonReader : {
                    cell: "",
                    id: "0"
                },
                url: 'SomeUrl/Getdata',
                datatype: 'jsonstring',
                mtype: 'POST',
                datastr : colD,
                colNames:colN,
                colModel :colM,
                pager: jQuery('#pager'),
                rowNum: 5,
                rowList: [5, 10, 20, 50],
                viewrecords: true
            })
       },
       error: function(x, e)
       {
            alert(x.readyState + " "+ x.status +" "+ e.msg);   
       }
    });
setTimeout(function() {$("#list").jqGrid('setGridParam',{datatype:'json'}); },50);

【讨论】:

  • 谢谢你的回复.....但是我没看懂,请你给我解释一下
  • 你可以试试上面的方法吗?
  • 请您说出我们需要在函数(结果)中获得“结果”的内容。对我来说它显示错误
  • 在 url 中,我需要提到的是,我在数据表中的数据与在 defaulst.aspx.cs 文件中的 getdata mehtod 中具有数据,我如何访问它?还请你说一下我们需要在函数(结果)中获得“结果”吗?对我来说它显示错误
猜你喜欢
  • 1970-01-01
  • 2011-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 2011-07-03
  • 2011-07-07
相关资源
最近更新 更多