Can a dropdownlist be filtered according to the letters that you enter?

0

I have the following DropDowList

<asp:DropDownList ID="DropAgent" runat="server" CssClass="form-control"></asp:DropDownList>

That filled in the following way with c#

IList<mg1DAO> resultList = new List<mg1DAO>();
resultList = ObjConnectorAgent.findAll();
DropAgent.Items.Add(new ListItem("Seleccione una opción","0"));
DropAgent.AppendDataBoundItems = true;
DropAgent.DataSource = resultList;
DropAgent.DataTextField = "CNOMBREA01";
DropAgent.DataValueField = "CIDAGENTE";
DropAgent.DataBind();

What I want to know is if you can convert or there is a way that the DropDownList is like a input where I am entering a letter and this in turn throws me the coincidences

    
asked by Miguel 29.06.2017 в 22:34
source

2 answers

1

The solution to my question was thanks to the help of a plugin called chosen

Its use is too simple, then I give you an example of what you do

I have the following DropDownList

<asp:DropDownList ID="DropAgent" runat="server" CssClass="form-control"></asp:DropDownList>

That filled in the following way with c #

IList<mg1DAO> resultList = new List<mg1DAO>();
resultList = ObjConnectorAgent.findAll();
DropAgent.Items.Add(new ListItem("Seleccione una opción","0"));
DropAgent.AppendDataBoundItems = true;
DropAgent.DataSource = resultList;
DropAgent.DataTextField = "CNOMBREA01";
DropAgent.DataValueField = "CIDAGENTE";
DropAgent.DataBind();

The only thing you did was add the following class to the asp DropDownList control

CssClass="chosen-select form-control"

The result is as follows

<asp:DropDownList ID="DropClientQuotation" runat="server" CssClass="chosen-select form-control">

Besides that also, we have to create a file js , which will be the one that helps us to start the plugin. With the following code lines

$(document).ready(function () {
    $('.chosen-select').chosen();
    $('.chosen-container').css('width', '100%');
});
    
answered by 14.09.2017 / 22:35
source
0

You can use select2 where you customize your search as a searchbox.

Here is an example based on the code you provided us.

$(document).ready(function(){
   $("#<%= DropAgent.ClientId %>").select2()
});
    
answered by 29.06.2017 в 22:44