Jqgrid is a good jquery based DataGrid framework, presumably everyone is not unfamiliar, online based on ASP data is very little, I provide a data format is JSON:
, a JSON class for Jqgrid: This code seems to be translated from some PHP in the website forum, we Save as json.asp, the code pastes:
Copy Code code as follows:
<%
Response. charset= "Utf-8"
'---------------------------------------
' Jsonclass class
' Converts the result of a SELECT statement to JSON
'------------------------------------------
Class Jsonclass
' Define class properties, default to Private
Dim sqlstring ' for setting Select
Dim json ' Returns the name of the JSON object
Dim dbconnection ' Connection object connected to the database
' Public methods that can be invoked externally
Public Function Getjson ()
Dim Rs
Dim returnstr
Dim i
Dim Onerecord
' Get Data
Set rs= Server.CreateObject ("ADODB.") Recordset ")
Rs.Open sqlstring,dbconnection,1,1
If page<> "" Then
Epage=cint (page)
If Epage<1 then epage=1
If Epage>rs.pagecount then Epage=rs.pagecount
Else
Epage=1
End If
Rs.pagesize = Rows
Rs.absolutepage = Epage
' Generate a JSON string
If Rs.eof=false and Rs.bof=false then
Returnstr= "{total: & rs.pagecount &", page: "& Page &", Records: "& Rs.recordcount &", rows:["
For J=0 to Rs.pagesize-1
If Rs.bof or rs.eof then exit for
' -------
' Onerecord = ' {id: ' & chr (0) &rs.fields. VALUE&CHR & ", cell:[" & Chr (&rs.fields) (0). VALUE&CHR & ","
Onerecord = "{id:" & chr (0) &rs.fields. VALUE&CHR & ", cell:[" & Chr (&rs.fields) (0). VALUE&CHR & ","
For I=1 to Rs.fields.count-1
' Onerecord=onerecord & Chr (&rs.fields) (i). NAME&CHR & ":"
Onerecord=onerecord & Chr (&rs.fields) (i). VALUE&CHR & ","
Next
' Remove the ', ' after the last field of the record
Onerecord=left (Onerecord,instrrev (Onerecord, ",")-1)
Onerecord=onerecord & "]},"
'------------
Returnstr=returnstr & Onerecord
Rs.movenext
Next
' After removing all the records array ', '
Returnstr=left (Returnstr,instrrev (Returnstr, ",")-1)
Returnstr=returnstr & "]}"
End If
Rs.close
Set rs=nothing
Getjson=returnstr
End Function
' Private method, used in the class
Private Function Check ()
End Function
'
End Class
%>
2, the production of display data ASP files, such as: List.asp, code as follows
Copy Code code as follows:
<!--#include file= "conn.asp"-->
<!--#include file= "json.asp"-->
<%
Dim Page,rows,sidx,sord
page = Request. QueryString ("page") ' Page '
rows = Request. QueryString ("Rows") ' pagesize
Sidx = Request. QueryString ("Sidx") ' ORDER by??
Sord = Request. QueryString ("Sord")
If page= "" then page = 1 End If
If rows = "" Then rows = Ten 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
Server. scripttimeout=9000
Dim a
Set A=new Jsonclass
A.sqlstring= ' Select Id,title,nickname,pwd,lastlogintime from Admin ' &strWhere& ' & ' ORDER BY ' & Sidx & "" & Sord
A.dbconnection=conn
Response. Write (A.getjson ())
Conn.close ()
Set conn = Nothing
%>
Inside, the search code is covered. This basically realizes the reading, as for the Editurl file in Jqgrid, we call it edit.asp, the code is as follows:
Copy Code code as follows:
<%option explicit%>
<!--#include file= "config.asp"-->
<%
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, Pwd,lastlogintime) 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
' Response. Write strSQL
Dim Strsql,rs
Call OPENDB ()
Set rs = Conn.execute (strSQL)
Call Closedb ()
%>
This is the front index.html code.
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>ASP_jqGrid_Test</title>
<link rel= "stylesheet" type= "Text/css" href= "Jquery-ui-1.7.2.custom.css"/>
<link rel= "stylesheet" type= "Text/css" href= "Jqgrid.css"/>
<link rel= "stylesheet" type= "Text/css" href= "Ui.multiselect.css"/>
<script type= "Text/javascript" src= "Js/jquery.js" ></script>
<script type= "Text/javascript" src= "Js/cn.js" ></script>
<script type= "Text/javascript" src= "Js/jqgrid.js" ></script>
<body>
<table id= "DataGrid" class= "scroll" ></table>
<div id= "Pager" class= "scroll" style= "Text-align:center"; ></div>
</body>
<script type= "Text/javascript" >
JQuery ("#DataGrid"). Jqgrid ({
URL: ' list.asp ',
DataType: "JSON",
colnames:[' ID ', ' admin account ', ' admin nickname ', ' Password ', ' Last login time ',
Colmodel: [
{
Name: ' Id ',
Index: ' Id ',
Width:50
},
{
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:20
},
editrules:{
Edithidden:true
}
},
{
Name: ' Lastlogintime ',
Index: ' Lastlogintime ',
Align: ' right ',
editrules:{
Required:true
}
}], caption: "Administrator List",
Imgpath: '/images ',
Multiselect:true,
ROWNUM:20,
ROWLIST:[10,20,30],
Pager:jquery (' #pager '),
Sortname: ' Id ',
Viewrecords:true,
SortOrder: "Desc",
height:400,
width:600,
Editurl: "Edit.asp"
});
$ (' #DataGrid '). Navgrid (' #pager ', {
Refresh:true,
Edit:true,
Add:true,
Del:true,
Search:true,
SearchText: "Search",
EditText: "Change", AddText: "Tim", Deltext: "Delete"
});
</script>
Jqgrid, good things ~ ~