locked
Using of autoComleteExtender RRS feed

  • Question

  • User1503865340 posted

    Hi,

    I'm using autoCompleteExtender and I want to know how to eliminate users from typing words that are not in the suggestion list. For example if I type in the textbox 'ab' I'll get this list for choosing : 'abc', 'abd','abe','abf'. How to ensure that the user choose one word from this list and not typing other word that not include in the list like 'abdfgh'.

    Thanks,

    David

    Thursday, February 13, 2014 3:11 AM

Answers

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 19, 2014 12:49 AM
  • User-933407369 posted

    You can try using 'like' fuzzy query ,  seems as "  name like '@name%' “.

    Code Snippet:

     [WebMethod] 
    
        public string[] GetCountriesList(string prefixText) 
    
        { 
            DataSet dtst = new DataSet(); 
    
            SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); 
    
            string strSql = "SELECT CountryName FROM Tbl_Countries WHERE CountryName LIKE '" + prefixText + "%' "; 
    
            SqlCommand sqlComd = new SqlCommand(strSql, sqlCon); 
    
            sqlCon.Open(); 
    
            SqlDataAdapter sqlAdpt = new SqlDataAdapter(); 
    
            sqlAdpt.SelectCommand = sqlComd; 
    
            sqlAdpt.Fill(dtst); 
    
            string[] cntName = new string[dtst.Tables[0].Rows.Count]; 
    
            int i = 0; 
    
            try 
    
            { 
    
                foreach (DataRow rdr in dtst.Tables[0].Rows) 
    
                { 
    
                    cntName.SetValue(rdr["CountryName"].ToString(), i); 
    
                    i++; 
    
                } 
    
            } 
    
            catch { } 
    
            finally 
    
            { 
    
                sqlCon.Close(); 
    
            } 
    
            return cntName; 
    
        } 
    
    

    please check out the link for details:

    AJAX AutoCompleteExtender

    http://www.c-sharpcorner.com/UploadFile/munnamax/AutocompleteExtender08062007113854AM/AutocompleteExtender.aspx

    Hope it helps you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 19, 2014 4:57 AM

All replies

  • User361793021 posted

    Hi,

    If your using  DataReader object to obtain a row from the results of the query then you have to check for rows like

    if (sdatareader.HasRows)
    {
    //user select the correct data in autocomplete
    }
    else
    {
    //user select the some random 
    //you can clear the text and give nack the focus to autocomplete here
    }
    
    Hope it helps you

     

    Thursday, February 13, 2014 3:24 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 19, 2014 12:49 AM
  • User-933407369 posted

    You can try using 'like' fuzzy query ,  seems as "  name like '@name%' “.

    Code Snippet:

     [WebMethod] 
    
        public string[] GetCountriesList(string prefixText) 
    
        { 
            DataSet dtst = new DataSet(); 
    
            SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); 
    
            string strSql = "SELECT CountryName FROM Tbl_Countries WHERE CountryName LIKE '" + prefixText + "%' "; 
    
            SqlCommand sqlComd = new SqlCommand(strSql, sqlCon); 
    
            sqlCon.Open(); 
    
            SqlDataAdapter sqlAdpt = new SqlDataAdapter(); 
    
            sqlAdpt.SelectCommand = sqlComd; 
    
            sqlAdpt.Fill(dtst); 
    
            string[] cntName = new string[dtst.Tables[0].Rows.Count]; 
    
            int i = 0; 
    
            try 
    
            { 
    
                foreach (DataRow rdr in dtst.Tables[0].Rows) 
    
                { 
    
                    cntName.SetValue(rdr["CountryName"].ToString(), i); 
    
                    i++; 
    
                } 
    
            } 
    
            catch { } 
    
            finally 
    
            { 
    
                sqlCon.Close(); 
    
            } 
    
            return cntName; 
    
        } 
    
    

    please check out the link for details:

    AJAX AutoCompleteExtender

    http://www.c-sharpcorner.com/UploadFile/munnamax/AutocompleteExtender08062007113854AM/AutocompleteExtender.aspx

    Hope it helps you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 19, 2014 4:57 AM
  • User555306248 posted

    I would like to suggest to use ComboBox which will resolve your requirement

    http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/ComboBox/ComboBox.aspx

     

    Wednesday, February 19, 2014 10:46 PM