转自 原文
项目需要这样子一个功能,其他部门提的意见,只好去实现了哦,搞了好久才弄出来,分享一下。
1.前台页面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
2.GetCode.aspx
前台为空
后台代码:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class GetCode : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["q"] != null) { string key = Request.Params["q"].ToString(); string result = ""; SqlHelp sql = new SqlHelp(); string str = "select top 15 CustomCode from tCustomList where CustomCode like '" + key + "%'"; SqlDataReader dr = sql.ExecuteReader(str); while (dr.Read()) { result += dr["CustomCode"].ToString() + "\n"; } dr.Dispose(); sql.SqlClose(); if (result == "") result = "not exists"; Response.Write(result); } } }
3. jquery.autocomplete.js
Download from