Click here to Skip to main content
15,883,989 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a textbox and an autocomplete extender. The Code is executing perfectly. But I want open the list as and when I focus on the textbox.

Please suggest.
I used all these code.
ASP
<asp:TextBox ID="TextBox3" runat="server" Width="268px"                   ontextchanged="TextBox3_TextChanged" AutoPostBack="true" onblur="Change(this, event)" onfocus="Change(this, event)"></asp:TextBox>
           
<ajax:autocompleteextender ID="AutoCompleteExtender1"  runat="server" TargetControlID="TextBox3" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="10" ServiceMethod="GetCountries"
CompletionListCssClass="autocomplete_completionListElement"                 CompletionListItemCssClass="autocomplete_listItem"                CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem">
</ajax:autocompleteextender> 


[System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public static List<string> GetCountries(string prefixText)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString.ToString());
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from table1 where col1 like @id+'%'", con);
        cmd.Parameters.AddWithValue("@id", prefixText);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        List<string> CountryNames = new List<string>();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            CountryNames.Add(dt.Rows[i][0].ToString());
        }
        return CountryNames;
    }


please help me.
My question is "How to open the list of autocompleteextender, when my cursor focus the textbox".
Please help
Posted
Updated 22-Dec-12 18:18pm
v3

1 solution

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        AutoCompleteExtender1.ContextKey = "ace1";
    }

    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
    {
        string[] result = new string[6];
        for (int i = 0; i < 6; i++)
        {
            result[i] = prefixText + i.ToString();
        }
        return result;
    }


</script>


<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>


</head>
<body>


    <form id="form1" runat="server">
    <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />

    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <ajaxToolkit:AutoCompleteExtender MinimumPrefixLength="0" ID="AutoCompleteExtender1"
            ServiceMethod="GetCompletionList" runat="server" TargetControlID="TextBox1">
        </ajaxToolkit:AutoCompleteExtender>
    </div>

    </form>

</body>
</html>

You can certainly have a reference from it, like MinimumPrefixLength="0"
Source : ASP .NET Forum[^]
 
Share this answer
 
v2
Comments
[no name] 22-Dec-12 12:27pm    
Its opening the list at keydown but in keyup its getting hidden.
So no use of it.
please suggest any other ways

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