


ASP不刷新頁(yè)面篩選數(shù)據(jù)庫(kù)中的數(shù)據(jù)
如何不刷新頁(yè)面篩選從數(shù)據(jù)庫(kù)中篩選數(shù)據(jù)。方法有兩種:
1、采用雙列表框的方法
2、采用XML方法
本文主要介紹第一種方法:采用雙列表框的方法
編程思想:
采用雙列表框,其中一個(gè)為隱藏狀態(tài),另一個(gè)是顯示給用戶看的列表框。
程序開始將數(shù)據(jù)(如雇員姓名)分別裝進(jìn)兩個(gè)列表框中,當(dāng)用戶需要篩選雇員時(shí)首先將顯示列表框清空,再更據(jù)篩選條件將數(shù)據(jù)從隱藏列表框裝入顯示列表框中。
這樣即可實(shí)現(xiàn)不刷新頁(yè)面篩選數(shù)據(jù)庫(kù)中的內(nèi)容。
實(shí)現(xiàn):
下面以SQLSERVER為例,篩選NorthWind庫(kù)中Employees表的雇員名進(jìn)行說(shuō)明。
<html>
<head>
<title>不刷新頁(yè)面查詢的方法</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
</head>
<language="java">
functionsearch_onclick(){
//得到篩選雇員的名字
searchtext=window.searchContent.value;
//首先移除在所有查詢結(jié)果列表中的選項(xiàng)
j=searchObj.length;
for(i=j-1;i>=0;i--)
{
searchObj.remove(i);
}
if(searchtext!=""){
//顯示符合篩選條件的雇員
j=searchSource.length;
for(i=0;i<j;i++){
searchsource=searchSource.options(i).text;
k=searchsource.indexOf(searchtext);
if(k!=-1){
option1=document.createElement("option");
option1.text=searchsource;
option1.value=searchSource.options(i).value;
searchObj.add(option1);
}
}
}
else{
//如果沒(méi)有輸入查詢條件則顯示所有雇員
j=searchSource.length;
for(i=0;i<j;i++){
searchsource=searchSource.options(i).text;
option1=document.createElement("option");
option1.text=searchsource;
option1.value=searchSource.options(i).value;
searchObj.add(option1);
}
}
}
</>
<bodybgcolor="#FFFFFF"text="#000000">
<%
servername="wyb"'服務(wù)器名
user="sa"'用戶名
pw=""'用戶密碼
databasename="northwind"'數(shù)據(jù)庫(kù)名
setconn=server.CreateObject("adodb.connection")
conn.Open"DRIVER=SQLServer;SERVER="&servername&";UID="&user&";pwd="&pw&";DATABASE="& databasename
setrs=server.CreateObject("adodb.recordset")
sql="Selectemployeeid,lastnamefromemployeesorderbyemployeeid"
rs.Opensql,conn%>
<tablewidth="80%"border="1">
<tr>
<td>
<inputtype="text"name="searchContent">
<inputtype="button"name="Button"value="查 詢">
</td>
</tr>
<tr>
<td>查詢結(jié)果<br>
<selectname="searchObj"size="10">
<%dowhilenotrs.eof%>
<optionvalue="<%=rs("employeeid")%>"><%=rs("lastname")%></option>
<%rs.movenext
loop
%>
</select>
<selectname="searchSource"size="10"style="display:none">
<%
rs.movefirst
dowhilenotrs.eof%>
<optionvalue="<%=rs("employeeid")%>"><%=rs("lastname")%></option>
<%rs.movenext
loop
%>
</select>
</td>
</tr>
</table>
<%rs.close
setrs=nothing
%>
</body>
</html>
關(guān)鍵字:ASP、數(shù)據(jù)庫(kù)、服務(wù)器
新文章:
- CentOS7下圖形配置網(wǎng)絡(luò)的方法
- CentOS 7如何添加刪除用戶
- 如何解決centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS單網(wǎng)卡如何批量添加不同IP段
- CentOS下iconv命令的介紹
- Centos7 SSH密鑰登陸及密碼密鑰雙重驗(yàn)證詳解
- CentOS 7.1添加刪除用戶的方法
- CentOS查找/掃描局域網(wǎng)打印機(jī)IP講解
- CentOS7使用hostapd實(shí)現(xiàn)無(wú)AP模式的詳解
- su命令不能切換root的解決方法
- 解決VMware下CentOS7網(wǎng)絡(luò)重啟出錯(cuò)
- 解決Centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS下如何避免文件覆蓋
- CentOS7和CentOS6系統(tǒng)有什么不同呢
- Centos 6.6默認(rèn)iptable規(guī)則詳解