为什么jqgrid没有显示任何数据? [英] why jqgrid not showing any data?

查看:84
本文介绍了为什么jqgrid没有显示任何数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

default2.aspx.cs



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Data.Sql;
使用 System.Data.SqlClient;
使用 System.Data;
使用 System.Configuration;
使用 System.Web.Services;
使用 System.Web.Script.Services;
使用 MySql.Data.MySqlClient;

public partial class getdata:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{

}
public struct s_GridResult
{
public int 页面;
public int total;
public int 记录;
public s_RowData [] rows;

}
public struct s_RowData
{
public int id;
public string [] cell;
}
[WebMethod]
public static s_GridResult GetDataTable(< span class =code-keyword> string _search, string nd, int 行, int 页面,字符串 sidx,字符串 sord )
{

int startindex =(page - 1 ) ;
int endindex = page;
string sql = SELECT Code,CardCode ,EmployeeName FROM processeddata_table;

DataTable dt = new DataTable();
MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings [ 连接]的ConnectionString)。
MySqlDataAdapter adapter = new MySqlDataAdapter(sql,conn);
adapter.Fill(dt);
s_GridResult result = new s_GridResult();
列表< s_rowdata> rowsadded = new 列表< s_rowdata>();
int idx = 1 ;
foreach (DataRow row in dt.Rows)
{
s_RowData newrow = new s_RowData();
newrow.id = idx ++;
newrow.cell = new string [ 3 ]; // 总列数
newrow.cell [ 0 ] = row [ 0 ]。ToString();
newrow.cell [ 1 ] = row [ 1 ]。ToString();
newrow.cell [ 2 ] = row [ 2 ]。ToString();
rowsadded.Add(newrow);
}
result.rows = rowsadded.ToArray();
result.page = page;
result.total = dt.Rows.Count;
result.record = rowsadded.Count;
返回结果;
}


}





default2.aspx

 <%@       语言  =  C#    AutoEventWireup   =  true    CodeFile   =  Default2.aspx.cs   继承  =  getdata    %>  

< !DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd >

< html xmlns = http://www.w3.org/1999/xhtml >
< head id = Head1 runat = server >
< title > < < span class =code-leadattribute> / title
>
< link rel = 样式表 type = text / css media = screen href = 主题/ jquery-ui-1.8.2.custom.css / >
< link rel = 样式表 type = text / css media = screen href = 主题/ ui.jqgrid.css / >
< link rel = 样式表 type = text / css media = screen href = 主题/ style.css / >


< script < span class =code-attribute> type = text / javascript src = js / jquery-1.4.2.min.js > < / script >
< script 类型 = text / javascript src = js / jquery.json-2.2.min.js > < / script >
< script 类型 = text / javascript src = js /jquery-ui-1.8.4.custom.min.js\"> < / script >
< span class =code-keyword>< script type = text / javascript src = js / grid.locale-en.js > < / script >
< script type = text / javascript src = js / jquery.jqGrid.min.js > < < span class =code-keyword> / script >




< script 类型 = text / javascript >
$( document )。ready( function (){
$ .extend($。jgrid.defaults,
{datatype:' json'},
{ajaxGridOptions:{contentType: application / json
成功: function (data,textStatus){
if (textStatus == success){
var thegrid = $( #Grid1)[ 0 ];
thegrid.addJSONData(data.d);
thegrid.grid.hDiv.loading = false ;
switch (thegrid.p.loadui){
case 禁用
break ;
case enable
$( #load _ + thegrid.p.id).hide() ;
break ;
case block
$( #lui _ + thegrid.p.id).hide() ;
$( #load _ + thegrid.p.id).hide();
break ;
}
}
}
}




});


jQuery( #Grid1)。jqGrid( {
url:' Default2.aspx / GetDataTable'
datatype:< span class =code-string>' json'
mtype:' POST'
colNames:[' 代码'' CardCode' ' EmployeeName'],
colModel:[{name:' 代码',索引:' 代码',宽度: 200 },
{name :' CardCode',index:' CardCode',width: 300 },
{name:' EmployeeName',index:' EmployeeName',width: 300 }],
pager:' #pager',sortname:' id'
viewrecoreds: true
imgpath:' Themes / images'
serializeGridData: function (data){
返回 $ .toJSON(数据);
}


});
});






< / script >
< / head >
< body >
< 表格 id = form1 runat = server >
< table id = Grid1 class = scroll align = center width = 100% > < / table >
< div id = pager class = scroll style = text-align:center; >






< / div >
< /表格 >
< / body >
< / html >

解决方案

document )。ready( function (){


.extend(


.jgrid.defaults,
{datatype:' json'},
{ajaxGridOptions:{contentType: application / json
成功:< span class =code-keyword> function (data,textStatus){
if (textStatus == success){
var thegrid =

default2.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Web.Services;
using System.Web.Script.Services;
using MySql.Data.MySqlClient;

public partial class getdata : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public struct s_GridResult
    {
        public int page;
        public int total;
        public int record;
        public s_RowData[] rows;

    }
    public struct s_RowData
    {
        public int id;
        public string[] cell;
    }
    [WebMethod]
    public static s_GridResult GetDataTable(string _search, string nd, int rows, int page, string sidx, string sord)
    {

        int startindex = (page - 1);
        int endindex = page;
        string sql = "SELECT Code,CardCode,EmployeeName FROM processeddata_table";

        DataTable dt = new DataTable();
        MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
        MySqlDataAdapter adapter = new MySqlDataAdapter(sql, conn);
        adapter.Fill(dt);
        s_GridResult result = new s_GridResult();
        List<s_rowdata> rowsadded = new List<s_rowdata>();
        int idx = 1;
        foreach (DataRow row in dt.Rows)
        {
            s_RowData newrow = new s_RowData();
            newrow.id = idx++;
            newrow.cell = new string[3];  //total number of columns  
            newrow.cell[0] = row[0].ToString();
            newrow.cell[1] = row[1].ToString();
            newrow.cell[2] = row[2].ToString();
            rowsadded.Add(newrow);
        }
        result.rows = rowsadded.ToArray();
        result.page = page;
        result.total = dt.Rows.Count;
        result.record = rowsadded.Count;
        return result;
    }


}



default2.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="getdata" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
     <link rel="Stylesheet" type="text/css" media="screen" href="Themes/jquery-ui-1.8.2.custom.css" />
     <link rel="Stylesheet" type="text/css" media="screen" href="Themes/ui.jqgrid.css" />
     <link rel="Stylesheet" type="text/css" media="screen" href="Themes/style.css" />


     <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
     <script type="text/javascript" src="js/jquery.json-2.2.min.js"></script>
     <script type="text/javascript" src="js/jquery-ui-1.8.4.custom.min.js"></script>
     <script type="text/javascript" src="js/grid.locale-en.js"></script>
     <script type="text/javascript" src="js/jquery.jqGrid.min.js"></script>




      <script type="text/javascript" >
          $(document).ready(function () {
              $.extend($.jgrid.defaults,
                  { datatype: 'json' },
                  { ajaxGridOptions: { contentType: "application/json",
                      success: function (data, textStatus) {
                          if (textStatus == "success") {
                              var thegrid = $("#Grid1")[0];
                              thegrid.addJSONData(data.d);
                              thegrid.grid.hDiv.loading = false;
                              switch (thegrid.p.loadui) {
                                  case "disable":
                                      break;
                                  case "enable":
                                      $("#load_" + thegrid.p.id).hide();
                                      break;
                                  case "block":
                                      $("#lui_" + thegrid.p.id).hide();
                                      $("#load_" + thegrid.p.id).hide();
                                      break;
                              }
                          }
                      }
                  }




                  });


              jQuery("#Grid1").jqGrid({
                  url: 'Default2.aspx/GetDataTable',
                  datatype: 'json',
                  mtype: 'POST',
                  colNames: ['Code', 'CardCode', 'EmployeeName'],
                  colModel: [{ name: 'Code', index: 'Code', width: 200 },
                   { name: 'CardCode', index: 'CardCode', width: 300 },
                    { name: 'EmployeeName', index: 'EmployeeName', width: 300}],
                  pager: '#pager', sortname: 'id',
                  viewrecoreds: true,
                  imgpath: 'Themes/images',
                  serializeGridData: function (data) {
                      return $.toJSON(data);
                  }


              });
          });






     </script>
</head>
<body>
    <form id="form1" runat="server">
    <table id="Grid1" class="scroll" align="center" width="100%"></table>
    <div id="pager" class="scroll" style="text-align:center;">






    </div>
    </form>
</body>
</html>

解决方案

(document).ready(function () {


.extend(


.jgrid.defaults, { datatype: 'json' }, { ajaxGridOptions: { contentType: "application/json", success: function (data, textStatus) { if (textStatus == "success") { var thegrid =


这篇关于为什么jqgrid没有显示任何数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆