asp.net webservice中的自动完成文本框

编程入门 行业动态 更新时间:2024-10-19 01:17:26
本文介绍了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中的自动完成文本框

本文发布于:2023-11-24 22:57:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627224.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   自动完成   asp   net   webservice

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!