本文介绍了asp webservice中的自动完成文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用母版页并使用脚本打开一个弹出窗口。 这个弹出窗口有一个文本框。 我添加一个ajax文本框中的自动完成扩展程序。 运行并获取值并检查断点。 但不在文本框中显示自动值。 如何要解决这个问题吗? 预先谢谢.....
I use master page and use script to open a popup window. This popupwindow have one textbox. I add a ajax autocomplete extender in textbox. It run and get the values and I check the breakpoint. But not display the autovalues in textbox. How to do solve this problem? Advance thanks.....
<asp:TextBox ID="txtshare" Width="125px" MaxLength="50" runat="server"> <ajaxToolkit:autocompleteextender ID="aceSearch" runat="server" TargetControlID="txtshare" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="5" CompletionInterval="100" ServiceMethod="GetUsers" ServicePath="CloudlistService.asmx" CompletionListCssClass="field small-field" >
[WebMethod] public string[] GetUsers(string prefixText, int count) { //ADO.Net //string a=Session["ln"].ToString(); //SqlConnection cn = new SqlConnection(); con.Close(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); //String strCn = "Data Source=.\\sqlexpress;Initial Catalog=cloudlist;Integrated Security=True"; ///cn.ConnectionString = strCn; SqlCommand cmd = new SqlCommand(); //cmd.CommandType = CommandType.Text; string cmdtext = "select Username from users Where Username like @myParameter+'%'"; cmd.Parameters.AddWithValue("@myParameter", prefixText); //cmdtext += " and Listname = @Listname"; //cmd.Parameters.AddWithValue("@Listname", contextKey); cmd.CommandText = cmdtext; cmd.Connection = con; //cmd.Parameters.AddWithValue("@Listname", contextKey); try { con.Open(); cmd.ExecuteNonQuery(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); } catch { } finally { con.Close(); } dt = ds.Tables[0]; //Then return List of string(txtItems) as result List<string> userNames = new List<string>(); String dbValues; foreach (DataRow row in dt.Rows) { //String From DataBase(dbValues) dbValues = row["Username"].ToString(); dbValues = dbValues.ToLower(); userNames.Add(dbValues); } return userNames.ToArray(); }
推荐答案
看看第一行: Have a look at the first line: con.Close();
结论: 你不能关闭连接时运行/执行命令;)
Conclusion: You can''t run/execute command on closed connection ;)
更多推荐
asp.net webservice中的自动完成文本框
发布评论