<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(); }
con.Close();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)