jqGrid是一个优秀的基于jQuery的DataGrid框架
想必大伙儿也不陌生
网上基于ASP的资料很少
我提供一个
数据格式是json的
一个针对jqGrid的json类这段代码似乎是由官网论坛的一些PHP中转化而来我们存为jsonasp代码贴一下
复制代码 代码如下:
<%
responseCharset=utf
JSONClass类
将Select语句的执行结果转换成JSON
Class JSONClass
定义类属性默认为Private
Dim SqlString 用于设置Select
Dim JSON 返回的JSON对象的名称
Dim DBConnection 连接到数据库的Connection对象
可以外部调用的公共方法
Public Function GetJSON ()
dim Rs
dim returnStr
dim i
dim oneRecord
获取数据
Set Rs= ServerCreateObject(ADODBRecordset)
Rsopen SqlStringDBConnection
if page<> then
epage=cint(page)
if epage< then epage=
if epage>rspagecount then epage=rspagecount
else
epage=
end if
rspagesize = rows
rsabsolutepage = epage
生成JSON字符串
if Rseof=false and RsBof=false then
returnStr={ total: & rspagecount & page: & page & records: & rsrecordcount & rows:[
for j= to rspagesize
if rsbof or rseof then exit for
oneRecord = {id: & chr() &RsFields()Value&chr()&cell:[& chr() &RsFields()Value&chr()&
oneRecord = {id: & chr() &RsFields()Value&chr()&cell:[& chr() &RsFields()Value&chr()&
for i= to RsFieldsCount
oneRecord=oneRecord & chr() &RsFields(i)Name&chr()&:
oneRecord=oneRecord & chr() &RsFields(i)Value&chr() &
Next
去除记录最后一个字段后的
oneRecord=left(oneRecordInStrRev(oneRecord))
oneRecord=oneRecord & ]}
returnStr=returnStr & oneRecord
RsMoveNext
next
去除所有记录数组后的
returnStr=left(returnStrInStrRev(returnStr))
returnStr=returnStr & ]}
end if
Rsclose
set Rs=Nothing
GetJSON=returnStr
End Function
私用方法在类中使用
Private Function check()
End Function
End Class
%>
制作显示数据的asp文件如listasp代码如下
复制代码 代码如下:
<!#include file=connasp >
<!#include file=jsonasp >
<%
dim pagerowssidxsord
page = requestQueryString(page) page
rows = requestQueryString(rows) pagesize
sidx = requestQueryString(sidx) order by ??
sord = requestQueryString(sord)
if page= then page = end if
if rows = then rows = end if
if sidx = then sidx = id end if
if sord = then sord =asc end if
Dim strSearchOn strField strFieldData strSearchOper strWhere
strSearchOn = Request(_search)
If (strSearchOn = true) Then
strField = Request(searchField)
If (strField = id Or strField = Title Or strField = NickName) Then
strFieldData = Request(searchString)
strSearchOper = Request(searchOper)
construct where
strWhere = Where & strField
Select Case strSearchOper
Case bw : Begin With
strFieldData = strFieldData & %
strWhere = strWhere & LIKE & strFieldData &
Case eq : Equal
If(IsNumeric(strFieldData)) Then
strWhere = strWhere & = & strFieldData
Else
strWhere = strWhere & = & strFieldData &
End If
Case ne: Not Equal
If(IsNumeric(strFieldData)) Then
strWhere = strWhere & <> & strFieldData
Else
strWhere = strWhere & <> & strFieldData &
End If
Case lt: Less Than
If(IsNumeric(strFieldData)) Then
strWhere = strWhere & < & strFieldData
Else
strWhere = strWhere & <& strFieldData &
End If
Case le: Less Or Equal
If(IsNumeric(strFieldData)) Then
strWhere = strWhere & <= & strFieldData
Else
strWhere = strWhere & <= & strFieldData &
End If
Case gt: Greater Than
If(IsNumeric(strFieldData)) Then
strWhere = strWhere & > & strFieldData
Else
strWhere = strWhere & > & strFieldData &
End If
Case ge: Greater Or Equal
If(IsNumeric(strFieldData)) Then
strWhere = strWhere & >= & strFieldData
Else
strWhere = strWhere & >= & strFieldData &
End If
Case ew : End With
strWhere = strWhere & LIKE % & strFieldData &
Case cn : Contains
strWhere = strWhere & LIKE % & strFieldData & %
End Select
End if
End If
serverScriptTimeout=
dim a
set a=new JSONClass
aSqlstring=Select idTitleNickNamePwdLastLoginTime From Admin&strWhere& &order by & sidx & & sord
adbconnection=conn
responseWrite(aGetJSon())
connclose()
set conn = nothing
%>
里面把搜索的代码涵盖了这样基本实现了读至于jqGrid中的editurl的文件我们称其editasp代码如下
复制代码 代码如下:
<%Option Explicit%>
<!#include file=configasp>
<%
Dim strOper strID strNickName strTitle strPwd
strOper = Request(oper)
strID = Replace(Request(Id))
strTitle = Replace(Request(Title))
strNickName = Replace(Request(NickName))
strPwd = Replace(Request(Pwd))
Select Case strOper
Case add: Add Record
strSQL = Insert Into Admin (Title NickName PwdLastLoginTime) Values(&strTitle& &strNickName& &strPwd&Now())
Case edit: Edit Record
strSQL = Update Admin Set Title = &strTitle& NickName = &strNickName& Pwd = &strPwd& Where id = &strID
Case del: Delete Record
strSQL = Delete From Admin Where id = &strID
End Select
responseWrite strSQL
Dim strSQLrs
Call OpenDB()
Set rs = ConnExecute(strSQL)
Call CloseDB()
%>
这是前台l代码
复制代码 代码如下:
<!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN >
<html xmlns=>
<head>
<meta httpequiv=ContentType content=text/html; charset=utf />
<title>ASP_jqGrid_Test</title>
<link rel=stylesheet type=text/css />
<link rel=stylesheet type=text/css />
<link rel=stylesheet type=text/css />
<script type=text/javascript src=js/jqueryjs></script>
<script type=text/javascript src=js/cnjs></script>
<script type=text/javascript src=js/jqGridjs></script>
</head>
<body>
<table id=DataGrid class=scroll></table>
<div id=pager class=scroll style=textalign:center;></div>
</body>
</html>
<script type=text/javascript>
jQuery(#DataGrid)jqGrid({
url:listasp
datatype: json
colNames:[ID管理员账号管理员昵称密码上次登录时间]
colModel :[
{
name:Id
index:Id
width:
}
{
name:Title
index:Title
editable:true
editrules:{
required:true
}
}
{
name:NickName
index:NickName
editable:true
editrules:{
required:true
}
}
{
name:Pwd
index:Pwd
editable:true
edittype:password
hidden:true
editoptions:{
size:
}
editrules:{
edithidden:true
}
}
{
name:LastLoginTime
index:LastLoginTime
align:right
editrules:{
required:true
}
} ] caption:管理员列表
imgpath:/images
multiselect: true
rowNum:
rowList:[]
pager: jQuery(#pager)
sortname: Id
viewrecords: true
sortorder: desc
height:
width:
editurl:editasp
});
$(#DataGrid)navGrid(#pager{
refresh: true
edit: true
add: true
del: true
search: true
searchtext:搜
edittext:改addtext:添deltext:删
});
</script>
jqGrid好东西~~