asp搜索源码(asp查询分页技术的源代码)

本文目录
asp查询分页技术的源代码
《%
lx=request.QueryString("lx")
page=int(request.QueryString("page"))
set rs=server.createobject("adodb.recordset")
exec="select * from news where lx like ’%"+lx+"%’ order by id desc"
rs.open exec,conn,1,1
rs.PageSize =20
If page 《 1 Then page = 1
If page 》 rs.PageCount Then page = rs.PageCount
if not rs.eof then rs.AbsolutePage =page
%》
《TABLE width=546 height="379" border=0 align=center cellPadding=0
cellSpacing=0 bgcolor="#FFFFFF"
style="BORDER-RIGHT: #c8cfec 1px solid; BORDER-TOP: #c8cfec 1px solid; BORDER-LEFT: #c8cfec 1px solid; BORDER-BOTTOM: #c8cfec 1px solid"》
《TBODY》
《TR》
《TD align=middle valign="top"》
《TABLE style="BORDER-BOTTOM: #8b8b8b 1px solid" cellSpacing=0
cellPadding=0 width=536 border=0》
《TBODY》
《TR》
《TD width=194 background="image/b_26_14.gif" height=24》
《TABLE cellSpacing=0 cellPadding=0 width="100%" border=0》
《TBODY》
《TR》
《TD height=3》《/TD》《/TR》
《TR》
《TD》 《FONT
color=#ffffff》《%=lx%》《/FONT》《/TD》
《/TR》《/TBODY》《/TABLE》《/TD》
《TD width=29》《IMG height=24
src="image/b_26_15.gif" width=29》《/TD》
《TD align=right
background="image/b_26_16.gif"》
《TABLE cellSpacing=0 cellPadding=0 width="90%" border=0》
《TBODY》
《TR》
《TD height=3》《/TD》《/TR》
《TR》
《TD align="right"》《span class="l22"》 《/span》《/TD》
《/TR》《/TBODY》《/TABLE》《/TD》
《TD width=11》《IMG height=24
src="image/b_26_17.gif"
width=11》《/TD》《/TR》《/TBODY》《/TABLE》
《TABLE cellSpacing=0 cellPadding=0 width="98%" border=0》
《TBODY》
《TR》
《TD height=6》《/TD》《/TR》《/TBODY》《/TABLE》
《TABLE cellSpacing=0 cellPadding=0 width=536 align=center border=0》
《TBODY》
《%For i = 1 To rs.PageSize
If rs.EOF Then Exit For
zt=rs("zt")
szt=xszh(zt)
if len(szt)》30 then szt=left(szt,30)+".." end if
%》
《TR》
《TD width=29 height="20" align=right》《img src="image/b_26_28.gif" width="11" height="7"》《/TD》
《TD width=507》
《A href="show.asp?id=《%=rs("id")%》" title="《%=zt%》" target="_blank"》
《%=szt%》(《%=rs("sj")%》)《/A》《/TD》
《/TR》
《% rs.movenext
next%》
《/TBODY》《/TABLE》
《TABLE cellSpacing=0 cellPadding=0 width="99%" border=0》
《TBODY》
《TR》
《TD width="4%" height="20" 》《p》 《/p》《/TD》
《TD 》
《center》
第
《%for i=1 to rs.PageCount
if i=page then
response.write i
else%》
《a href="list.asp?lx=《%=lx%》&page=《%=i%》"》《/a》
《% end if
next%》
页
《/center》
《/TD》
《TD width="4%" 》 《/TD》
《/TR》《/TBODY》《/TABLE》《/TD》
《/TR》《/TBODY》《/TABLE》
asp搜索源码
Set rs= Server.CreateObject("ADODB.Recordset")
key=reqeust.form("key")
otype=reqeust.from("otype")
if otype="title" then
sql="select * from NEWS where title Like ’%"& key &"%’ order by id desc"
else
sql="select * from NEWS where content Like ’%"& key &"%’ order by id desc"
end if
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "《p align=’center’》对不起,没有找到相关文章《/p》"
else
ajax asp.net智能匹配完成搜索完整源码
ASP.net+AJAX智能匹配检索(自动完成)
实例说明
使用谷歌搜索引擎,用户只要输入部分关键字,就能够显示相关搜索提示信息列表。那么在这里我们通过ASP.NET来实现这样的功能,程序运行结果如图18.2所示。
图18.2 智能匹配检索
技术要点
本实例的核心技术是通过ASP.NET AJAX Control Toolkit中的AutoCompleteExtender控件实现。
AutoCompleteExtender控件实现自动输入建议的功能,通过调用WebService或本页面对应的方法名来获取提示数据,供用户能达到自动选择的功能。AutoCompleteExtender控件的主要属性及说明如表18.2所示。
表18.2 AutoCompleteExtender控件的主要属性及说明
属性
说明
TargetControlID
指定将被辅助完成自动输入的控件ID,这里的控件只能是TextBox
ServicePath
指出提供服务的WEB服务路径,若不指出则ServiceMethod表示本页面对应的方法名
ServiceMethod
指出提供服务的方法名,例如public string Method(string prefixText, int count),其中参数prefixText是用户输入的关键字;参数count是所需要获取提示数据的数量;两个参数都会自动传给WebService的ServiceMethod方法),返回值是用户所获得提示数据的来源数组。
MinimumPrefixLength
指出开始提供提示服务时,TextBox控件应有的最小字符数,默认值为3
CompletionInterval
从服务器读取数据的时间间隔,默认为1000,单位:毫秒。
EnableCaching
是否在客户端缓存数据,默认为true
CompletionSetCount
显示的条数,默认值为10
实现过程
(1)新建一个AJAX网站,将其命名为Ex08_02,默认主页为Default.aspx。
(2)在Default.aspx页中主要添加一个ScriptManager控件、一个AutoCompleteExtender控件和一个TextBox控件,其中ScriptManager控件主要用于管理Web页面中的AJAX控件,AutoCompleteExtender控件实现自动完成功能,TextBox控件接收输入检索关键字。
(3)创建一个Web服务,将其命名为KeyFind.asmx,该服务主要完成智能检索功能。
(4)在KeyFind.asmx Web服务的KeyFind.cs文件下实现代码如下:
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
//引入空间
using System.Data;
using System.Data.OleDb;
using System.Configuration;
/// 《summary》
/// KeyFind 的摘要说明
/// 《/summary》
***隐藏网址***
//添加服务脚本(必须添,否则程序不能正常运行)
public class KeyFind : System.Web.Services.WebService
{
public KeyFind()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
//定义数组保存获取的内容
private string autoCompleteWordList = null;
//两个参数“prefixText”表示用户输入的前缀,count表示返回的个数
public String GetCompleteDepart(string prefixText, int count)
{
///检测参数是否为空
if (string.IsNullOrEmpty(prefixText) == true || count 《= 0) return null;
// 如果数组为空
if (autoCompleteWordList == null)
{
//读取数据库的内容
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Ex18_02.mdb"));
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter("select keyName from keyInfo where keyName like’" + prefixText + "%’ order by keyName", conn);
DataSet ds = new DataSet();
da.Fill(ds);
//读取内容文件的数据到临时数组
string;
int i = 0;
foreach (DataRow dr in ds.Tables.Rows)
{
temp.ToString();
i++;
}
Array.Sort(temp, new CaseInsensitiveComparer());
//将临时数组的内容赋给返回数组
autoCompleteWordList = temp;
if (conn.State == ConnectionState.Open)
conn.Close();
}
//定位二叉树搜索的起点
int index = Array.BinarySearch(autoCompleteWordList, prefixText, new CaseInsensitiveComparer());
if (index 《 0)
{ //修正起点
index = ~index;
}
//搜索符合条件的数据
int matchCount = 0;
for (matchCount = 0; matchCount 《 count && matchCount + index 《 autoCompleteWordList.Length; matchCount++)
{ ///查看开头字符串相同的项
if (autoCompleteWordList.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) == false)
{
break;
}
}
//处理搜索结果
string;
if (matchCount 》 0)
{ //复制搜索结果
Array.Copy(autoCompleteWordList, index, matchResultList, 0, matchCount);
}
return matchResultList;
}
}
(5)回到Default.aspx页的源视图,设置其AutoCompleteExtender控件属性值,代码如下:
《cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1"
ServicePath="KeyFind.asmx" CompletionSetCount="10" MinimumPrefixLength="1" ServiceMethod="GetCompleteDepart"》
《/cc1:AutoCompleteExtender》

更多文章:
数据库管理系统和数据库系统分别侧重(数据库,数据库管理系统,数据库系统,这三个分别是什么意思并举个实例)
2026年9月7日 17:00
springmvc的依赖(springMVC的注入方式有哪几种,这与springMVC依赖)
2026年9月7日 14:00
display flex 自动换行(overflow-y:hidden;overflow-x:auto;无效解决方法)
2026年9月7日 11:00
timestamp without time zone(Postgresql中to_date()函数使用问题)
2026年9月7日 09:40






