Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Ajax WinForm
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: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 21-Dec-12 9:53am
(unknown member)
Edited 22-Dec-12 18:18pm
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

<%@ 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[^]
  Permalink  
v2
Comments
Sourav Sarkar-SS2 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 354
1 Richard MacCutchan 310
2 OriginalGriff 275
3 Vinay Mistry 163
4 Jared Sanow 145
0 Sergey Alexandrovich Kryukov 5,939
1 OriginalGriff 4,885
2 CPallini 2,473
3 Abhinav S 1,507
4 Richard MacCutchan 1,437


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 23 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100