佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > ASP 使用jqGrid實(shí)現(xiàn)讀寫(xiě)刪的代碼(json)

ASP 使用jqGrid實(shí)現(xiàn)讀寫(xiě)刪的代碼(json)

熱門(mén)標(biāo)簽:Mysql連接數(shù)設(shè)置 阿里云 電子圍欄 銀行業(yè)務(wù) Linux服務(wù)器 團(tuán)購(gòu)網(wǎng)站 服務(wù)器配置 科大訊飛語(yǔ)音識(shí)別系統(tǒng)
jqGrid是一個(gè)優(yōu)秀的基于jQuery的DataGrid框架,想必大伙兒也不陌生,網(wǎng)上基于ASP的資料很少,我提供一個(gè),數(shù)據(jù)格式是json的:
、一個(gè)針對(duì)jqGrid的json類(lèi):這段代碼似乎是由官網(wǎng)論壇的一些PHP中轉(zhuǎn)化而來(lái),我們存為json.asp,代碼貼一下:
復(fù)制代碼 代碼如下:

%
response.Charset="utf-8"
'---------------------------------------
' JSONClass類(lèi)
' 將Select語(yǔ)句的執(zhí)行結(jié)果轉(zhuǎn)換成JSON
'------------------------------------------
Class JSONClass
' 定義類(lèi)屬性,默認(rèn)為Private
Dim SqlString ' 用于設(shè)置Select
Dim JSON ' 返回的JSON對(duì)象的名稱(chēng)
Dim DBConnection ' 連接到數(shù)據(jù)庫(kù)的Connection對(duì)象
' 可以外部調(diào)用的公共方法
Public Function GetJSON ()
dim Rs
dim returnStr
dim i
dim oneRecord
' 獲取數(shù)據(jù)
Set Rs= Server.CreateObject("ADODB.Recordset")
Rs.open SqlString,DBConnection,1,1
if page>"" then
epage=cint(page)
if epage1 then epage=1
if epage>rs.pagecount then epage=rs.pagecount
else
epage=1
end if
rs.pagesize = rows
rs.absolutepage = epage
' 生成JSON字符串
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(34) Rs.Fields(0).Valuechr(34)",cell:[" chr(34) Rs.Fields(0).Valuechr(34)","
oneRecord = "{id:" chr(34) Rs.Fields(0).Valuechr(34)",cell:[" chr(34) Rs.Fields(0).Valuechr(34)","
for i=1 to Rs.Fields.Count -1
'oneRecord=oneRecord chr(34) Rs.Fields(i).Namechr(34)":"
oneRecord=oneRecord chr(34) Rs.Fields(i).Valuechr(34) ","
Next
'去除記錄最后一個(gè)字段后的","
oneRecord=left(oneRecord,InStrRev(oneRecord,",")-1)
oneRecord=oneRecord "]},"
'------------
returnStr=returnStr oneRecord
Rs.MoveNext
next
' 去除所有記錄數(shù)組后的","
returnStr=left(returnStr,InStrRev(returnStr,",")-1)
returnStr=returnStr "]}"
end if
Rs.close
set Rs=Nothing
GetJSON=returnStr
End Function
'私用方法,在類(lèi)中使用
Private Function check()
End Function
'
End Class
%>

2、制作顯示數(shù)據(jù)的asp文件,如:list.asp,代碼如下
復(fù)制代碼 代碼如下:

!--#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 = 10 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
%>

里面把搜索的代碼涵蓋了。這樣基本實(shí)現(xiàn)了讀,至于jqGrid中的editurl的文件,我們稱(chēng)其edit.asp,代碼如下:
復(fù)制代碼 代碼如下:

%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()
%>

這是前臺(tái)index.html代碼
復(fù)制代碼 代碼如下:

!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>
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>
/head>
body>
table id="DataGrid" class="scroll">/table>
div id="pager" class="scroll" style="text-align:center;">/div>
/body>
/html>
script type="text/javascript">
jQuery("#DataGrid").jqGrid({
url:'list.asp',
datatype: "json",
colNames:['ID','管理員賬號(hào)','管理員昵稱(chēng)','密碼','上次登錄時(shí)間'],
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:"管理員列表",
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:"搜",
edittext:"改",addtext:"添",deltext:"刪"
});
/script>

jqGrid,好東西~~
您可能感興趣的文章:
  • jqGrid隨窗口大小變化自適應(yīng)大小的示例代碼
  • Jqgrid設(shè)置全選(選擇)及獲取選擇行的值示例代碼
  • JQGrid的用法解析(列編輯,添加行,刪除行)
  • jquery增加時(shí)編輯jqGrid(實(shí)例代碼)
  • jQuery中jqGrid分頁(yè)實(shí)現(xiàn)代碼
  • 一個(gè)關(guān)于jqGrid使用的小例子(行按鈕)
  • 給jqGrid數(shù)據(jù)行添加修改和刪除操作鏈接(之一)
  • jqGrid jQuery 表格插件測(cè)試代碼
  • jqgrid 簡(jiǎn)單學(xué)習(xí)筆記
  • jQuery jqgrid 對(duì)含特殊字符json 數(shù)據(jù)的 Java 處理方法
  • jquery下動(dòng)態(tài)顯示jqGrid以及jqGrid的屬性設(shè)置容易出現(xiàn)問(wèn)題的解決方法
  • jqGrid 學(xué)習(xí)筆記整理——進(jìn)階篇(一 )

標(biāo)簽:棗莊 萍鄉(xiāng) 衡水 廣元 衢州 蚌埠 江蘇 大理

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP 使用jqGrid實(shí)現(xiàn)讀寫(xiě)刪的代碼(json)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話(huà)咨詢(xún)

    • 400-1100-266
    石首市| 墨脱县| 十堰市| 左云县| 鄂尔多斯市| 顺义区| 盱眙县| 丰顺县| 双城市| 临猗县| 曲水县| 郯城县| 探索| 荣昌县| 信阳市| 杂多县| 德化县| 波密县| 涞水县| 勃利县| 江安县| 景宁| 天长市| 鹤峰县| 遂宁市| 澄城县| 边坝县| 衡东县| 鱼台县| 桂阳县| 枝江市| 乐业县| 怀仁县| 拜泉县| 昌江| 鄢陵县| 涞水县| 桑植县| 昂仁县| 南郑县| 和田县|