Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
3.40/5 (2 votes)
See more:
I am using combo box to show supplier name. In search facility when user type “S” in combo box the entire supplier’s list should be display whose name start form “S”, like country, state search facility in any web based application. Same way as per user inputs list should be change.
Can any one know logic behind this
Posted
Updated 10-Jul-13 4:05am
v4

You need to use autocomplete ajax extender. Look at this article for description and sample: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx[^]
 
Share this answer
 
hey try to use autocomplete extender instead of Conbobox..
Refer Below Link.
AutoComplete extender[^]
ASP.Net Ajax AutoCompleteExtender Without Using Web Service[^]
 
Share this answer
 
This funcionality is called auto-complete
first of all you will need this js file:
XML
jquery-ui-1.8.20.custom.min.js

and css file:
XML
jquery-ui-1.8.20.custom.css


1.place link of these files on page where you want to use auto-complete just like this:
HTML
<script src="Scripts/jquery-ui-1.8.20.custom.min.js" type="text/javascript"></script>
   <link href="Styles/jquery-ui-1.8.20.custom.css" rel="stylesheet" type="text/css" />


2.then use this script:
JavaScript
    <script type="text/javascript">
        $(document).ready(function () {
            $('input[id$=textboxid]').autocomplete({
                source: function (request, response) {
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "pagename.aspx/getReason",
                        data: "{'keywords':'" + request.term + "'}",
                        dataType: "json",
                        async: true,
                        success: function (data) {
                            response(data.d);
                        },
                        error: function (result) {
                            //alert("Error");
                        }
                    });
                },
                minLength: 2
            });

        });
</script>

3.then add this method in code behind (.cs) file:
C#
[WebMethod]
   public static IList<string> getReason(string keywords)
   {
       int count = 0;
       IList<string> result = new List<string>();
       string constr = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
       SqlConnection con1 = new SqlConnection(constr);
       SqlCommand cmd1 = con1.CreateCommand();
       cmd1.CommandText = "select distinct column_name from tablename where column_name like '%" + keywords + "%'";
       try
       {
           con1.Open();
           SqlDataReader dr = cmd1.ExecuteReader();
           while (dr.Read())
           {
               count++;
               result.Add(dr["column_name"].ToString());
               if (count == 100)
                   break;
           }
           con1.Close();
           return result;
       }
       catch
       {
           return null;
       }
   }
 
Share this answer
 
v3

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