Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.....
XML
<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" >

C#
[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();
    }
Posted
v3
Comments
ZurdoDev 20-Mar-13 10:19am    
You'll have to post relevant code.
bbirajdar 20-Mar-13 10:33am    
The problem is in the fourth line in the code. Correct it..
[no name] 20-Mar-13 17:07pm    
The first thing to do is to get rid of the empty catch block. Either display the error to the user or log it. That is kind of important information.

1 solution

Have a look at the first line:
VB
con.Close();


Conclusion:
You can't run/execute command on closed connection ;)
 
Share this answer
 
v2
Comments
Orcun Iyigun 21-Mar-13 2:36am    
You can or you can't :)
Maciej Los 21-Mar-13 2:48am    
Of course: "can't".
Thank you, Orcun ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900