日期:2014-05-18 浏览次数:20410 次
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1" ServiceMethod="GetCompletionList" CompletionSetCount="10" CompletionInterval="500" MinimumPrefixLength="1"> </ajaxToolkit:AutoCompleteExtender> </div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </form> </body> </html>
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { static SqlConnection conn; protected void Page_Load(object sender, EventArgs e) { conn = new SqlConnection(@"server=.\SQL2000;database=JHCRM;uid=sa;pwd=sa"); } [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()] public static string[] GetCompletionList(string prefixText,int count) { conn.Open(); string sql = "SELECT YGID,YGNAME FROM TEMP_YG WHERE YGPY LIKE '" + prefixText + "%'"; SqlDataAdapter da = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); da.Fill(ds); conn.Close(); int i = 0; string[] temp = new string[ds.Tables[0].Rows.Count]; foreach (DataRow dr in ds.Tables[0].Rows) { temp[i] = dr[1].ToString(); i++; } return temp; } }