webservice 如下: using System; using System.Web; using System.Collections; using System.Web.Services; using System.Web.Services.Protocols; using System.Data.SqlClient; using System.Data; using AjaxControlToolkit; /// <summary> /// AutoCompleteService 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService()] public class AutoCompleteService : System.Web.Services.WebService { public AutoCompleteService () { //如果使用设计的组件,请取消注释以下行 //InitializeComponent(); } [WebMethod] public string[] getWordList(string prefixText, int count) { string sqlstr = " Data Source=QINGDAOD-3000A2;Initial Catalog=Score;User ID=hyslove;Password=hyslove"; SqlConnection sqlconn=new SqlConnection(sqlstr); string mysql="select name from Student where name like"+"'"+ prefixText+"%'"; SqlDataAdapter da=new SqlDataAdapter(mysql,sqlconn); DataSet ds =new DataSet(); da.Fill(ds,"studentname"); string[] returnvalue=new string [ds.Tables["studentname"].Rows.Count]; for(int i=1;i<=ds.Tables["studentname"].Rows.Count;i++) { returnvalue[i-1]=ds.Tables["studentname"].Rows[i-1][0].ToString(); } return(returnvalue); } } AutoCompleteExtender的属性设置如下 <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1" ServicePath="AutoCompleteService.asmx" ServiceMethod="getWordList" MinimumPrefixLength="1"> </cc1:AutoCompleteExtender> 其中MinimumPrefixLength="1" 表示输入一个字符就提示显示。 |
AutoCompleteExtender实现自动完成功能(从数据库中读取数据 )
最新推荐文章于 2014-08-02 11:36:36 发布
2007-07-12 10:45