0

I have a simple asp.net Textbox and a search button next to it. The user would write some text in the Textbox and then click search. When the search button is clicked, I need to perform data retrieval and display the results in a dropdownlist below the textbox.

Please check the image below for illustration: enter image description here

So far I display the results in a separate GridView, how can I display it as a dropdown as shown?

Community
  • 1
  • 1
user3340627
  • 3,023
  • 6
  • 35
  • 80

3 Answers3

0

YOu can add item in dropdown using datatable or simply strings.

  1. Using strings

    ddl.Items.Add(new ListItem("Item 1", "Value 1"));

    ddl.Items.Add(new ListItem("Item 2", "Value 2"));

    ddl.Items.Add(new ListItem("Item 3", "Value 3"));

  2. Using DataTable

    ddl.DataTextField = "ColumnName1";

    ddl.DataValueField = "ColumnName2"

    //dt is DataTable

    ddl.DataSource = dt;

    ddl.DataBind()

Jigneshk
  • 350
  • 1
  • 7
0

May you can use this property if you already knows the datas :

https://msdn.microsoft.com/fr-fr/library/system.windows.forms.textbox.autocompletemode%28v=vs.110%29.aspx

Or you can search in database and display result with a JQuery autocomplete and Ajax Call.

Efficient way of using JQuery UI Autocomplete with ASP.NET

Community
  • 1
  • 1
Julien698
  • 676
  • 3
  • 10
  • 27
0

Why you are using button when there is autocomplete function in jquery?.it is work when user type text in textbox instead of click the button It is easy for user to search

refer link

https://jqueryui.com/autocomplete/

http://code.runnable.com/UdQOiCHniSpKAAV1/add-autocomplete-to-input-box-form-using-jquery

http://dotnetcodepress.com/Articles/ASP-dot-net/jquery-ui-autocomplete-textbox-from-database-in-asp-net

user3340627
  • 3,023
  • 6
  • 35
  • 80
Rita Chavda
  • 191
  • 2
  • 16