jqGrid未使用JSON显示SQL Server数据
这件事我已经搞了好几天了,我都快发疯了。我能够使用“本地”数据类型使jqGrid工作,现在我正试图将其与SQL数据绑定。我没有错误,只是一个空白网格。我在网上搜索了很多例子,但都没有成功。将显示网格并显示列标题,但没有数据。我也没有收到js错误。我对分页、排序、搜索等不感兴趣。。。在这一点上。只需要让数据显示出来。有人能给我指出正确的方向吗jqGrid未使用JSON显示SQL Server数据,sql,vb.net,json,jqgrid,Sql,Vb.net,Json,Jqgrid,这件事我已经搞了好几天了,我都快发疯了。我能够使用“本地”数据类型使jqGrid工作,现在我正试图将其与SQL数据绑定。我没有错误,只是一个空白网格。我在网上搜索了很多例子,但都没有成功。将显示网格并显示列标题,但没有数据。我也没有收到js错误。我对分页、排序、搜索等不感兴趣。。。在这一点上。只需要让数据显示出来。有人能给我指出正确的方向吗 VB.NET code: ============ Public Function GetGridData() As JqGridData Dim
VB.NET code:
============
Public Function GetGridData() As JqGridData
Dim sql As String = "Select unit_number, product_code, blood_type, 'No Match' scan_result From product_header Where (product_id < 20) Order By 1, 2, 3"
Dim dt As New DataTable()
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("conn").ConnectionString)
Dim adapter As New SqlDataAdapter(sql, conn)
adapter.Fill(dt)
Dim result As New JqGridData()
Dim gridRows As New List(Of TableRow)()
Dim idx As Integer = 1
For Each row As DataRow In dt.Rows
Dim newrow As New TableRow()
newrow.id = idx
newrow.cell = New List(Of String)(4)
newrow.cell(0) = row(0).ToString()
newrow.cell(1) = row(1).ToString()
newrow.cell(2) = row(2).ToString()
newrow.cell(3) = row(3).ToString()
gridRows.Add(newrow)
Next
result.total = 2
result.page = 1
result.records = gridRows.Count
result.rows = gridRows
Return result
End Function
Public Class TableRow
Private m_id As Integer
Private m_cell As List(Of String)
Public Property id() As Integer
Get
Return m_id
End Get
Set(ByVal value As Integer)
m_id = value
End Set
End Property
Public Property cell() As List(Of String)
Get
Return m_cell
End Get
Set(ByVal value As List(Of String))
m_cell = value
End Set
End Property
End Class
Public Class JqGridData
Private m_total As Integer
Private m_page As Integer
Private m_records As Integer
Private m_rows As List(Of TableRow)
Public Property total() As Integer
Get
Return m_total
End Get
Set(ByVal value As Integer)
m_total = value
End Set
End Property
Public Property page() As Integer
Get
Return m_page
End Get
Set(ByVal value As Integer)
m_page = value
End Set
End Property
Public Property records() As Integer
Get
Return m_records
End Get
Set(ByVal value As Integer)
m_records = value
End Set
End Property
Public Property rows() As List(Of TableRow)
Get
Return m_rows
End Get
Set(ByVal value As List(Of TableRow))
m_rows = value
End Set
End Property
End Class
js code:
========
$(document).ready(function(){
$("#list").jqGrid({
url: 'Display.aspx/GetGridData',
datatype: 'json',
mtype: "GET",
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (data) {
return JSON.stringify(data);
},
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: true
},
colModel: [
{name: 'unit_number', label: 'Unit Number', width: 100, align: 'center'},
{name: 'product_code', label: 'Product Code', width: 200, align: 'center'},
{name: 'blood_type', label: 'Blood Type', width: 200, align: 'center'},
{name: 'scan_result', label: 'Scan Result', width: 200, align: 'center'}
],
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'id',
sortorder: "asc",
pager: "#pager",
viewrecords: true,
caption: 'My first grid'
}).jqGrid('navGrid', '#pager', {edit: false, add: false, del: false, search: true});
});
试着拔出
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (data) {
return JSON.stringify(data);
},
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: true
},
并确保传递jqGrid需要的所有数据。我不是一个VB.Net的家伙,所以我也假设你有一个控制器/动作,为你的网格提供数据?您还可以尝试手动为网格构建一行,以测试该特性 谢谢你的回复。在研究您的建议时,我在代码中发现了一些问题。我会解决这些问题,必要时再发布。