asp.net ajax控件工具集 AutoCompleteExtender控件
生活随笔
收集整理的這篇文章主要介紹了
asp.net ajax控件工具集 AutoCompleteExtender控件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
當我們在搜索框輸入關鍵字的時候,Google會自動列出相關關鍵字提示。用asp.net?Ajax?AutoCompleteExtender控件實現
運行環境行vs 2008 .net 3.5sp1?? 需單獨安裝ajax控件工具集
demo源碼下載
<%@?Page?Language="C#"?AutoEventWireup="true"?CodeFile="Default.aspx.cs"?Inherits="_Default"?%>
<%@?Register?Assembly="AjaxControlToolkit"?Namespace="AjaxControlToolkit"?TagPrefix="cc1"?%>
<!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?runat="server">
????<title>無標題頁</title>
</head>
<body>
????<form?id="form1"?runat="server">
????<div>
<asp:ScriptManager?ID="ScriptManager1"?runat="server"?/>
????????<asp:TextBox?ID="TextBox1"?runat="server"></asp:TextBox>
????????<cc1:AutoCompleteExtender?ID="AutoCompleteExtender1"?runat="server"?
????????????TargetControlID="TextBox1"?ServiceMethod="GetCompletionList"??CompletionSetCount="10"?MinimumPrefixLength="2"?EnableCaching="true"
????????????UseContextKey="True">
????????</cc1:AutoCompleteExtender>
????????
????
????</div>
????</form>
</body>
</html>
對應的cs代碼文件
Code
using?System;
using?System.Collections;
using?System.Configuration;
using?System.Data;
using?System.Linq;
using?System.Web;
using?System.Web.Security;
using?System.Web.UI;
using?System.Web.UI.HtmlControls;
using?System.Web.UI.WebControls;
using?System.Web.UI.WebControls.WebParts;
using?System.Xml.Linq;
using?System.Collections.Generic;
using?System.Data.SqlClient;
public?partial?class?_Default?:?System.Web.UI.Page
{
????[System.Web.Services.WebMethodAttribute(),
????System.Web.Script.Services.ScriptMethodAttribute()]
????public?static?string[]?GetCompletionList(string?prefixText,?int?count,
???????string?contextKey)
????{
????????SqlConnection?conn;
????????SqlCommand?cmd;
????????string?cmdString?=
???????????"Select?CompanyName?from?Customers?WHERE?CompanyName?LIKE?'"?+
???????????prefixText?+?"%'";
????????conn?=?new?SqlConnection(@"Data?Source=.;DataBase=Northwind;UID=sa;PWD=sa;");
????????//?Put?this?string?on?one?line?in?your?code
????????cmd?=?new?SqlCommand(cmdString,?conn);
????????conn.Open();
????????SqlDataReader?myReader;
????????List<string>?returnData?=?new?List<string>();
????????myReader?=?cmd.ExecuteReader(CommandBehavior.CloseConnection);
????????while?(myReader.Read())
????????{
????????????returnData.Add(myReader["CompanyName"].ToString());
????????}
????????return?returnData.ToArray();
????}
}
轉載于:https://www.cnblogs.com/honghu3000/archive/2009/01/08/1371968.html
總結
以上是生活随笔為你收集整理的asp.net ajax控件工具集 AutoCompleteExtender控件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Windows Azure Cloud
- 下一篇: 转 DevExpress-ASPxPag