You must Sign In to post a response.
  • Category: ASP.NET

    Editable dropdownlist

    Hi developers!

    i need a editable dropdownlist for populating data from database in asp.net
  • #761669
    Hi Gaurav.

    Can you provide more information regarding you question.
    How you wanat to edit the dropdownlist, from codebehind or at runtime on UI.

    Elaborate with more details so that any one can give you solution

    Regards

    Sridhar Thota.
    If you learn't from defeat..
    You haven't really lost..

    Sridhar Thota.
    Editor: DNS Forum.

  • #761671
    i want to edit dropdownlist at run time mode
    means fast search for my populated data in drop down.

    like i my dropdown following data is stored
    Car
    pen
    book
    stock
    mobile

    when i am enter 'o' then list show following data
    book
    stock
    mobile

    because 'o' is present in all words

  • #761676
    Hello Gaurav,

    Refer the below code :

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <cc1:ComboBox ID="ComboBox1" runat="server" AutoCompleteMode="SuggestAppend" MaxLength="0" style="display: inline;">
    </cc1:ComboBox>



    SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {
    try
    {
    DataTable dt = new DataTable();
    con.Open();
    SqlDataAdapter sda = new SqlDataAdapter("SELECT StudentName FROM Student", con);
    sda.Fill(dt);
    ComboBox1.DataSource = dt;
    ComboBox1.DataTextField = "StudentName";
    ComboBox1.DataValueField = "StudentName";
    ComboBox1.DataBind();
    }
    catch (Exception ex)
    {
    Response.Write(ex.StackTrace);
    }
    finally
    {
    con.Close();
    }
    }

    See the attached image as an output of using mentioned code.

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #761679
    Hi Nirav.

    His requirement is like a AutoComplete dropdown list.
    If we press "s" the names having "s" letter should be shown in the dropdown.
    In your output screen you pressed "N" but it is displaying all names.

    i think that can be achieved by using the below sql statement in the event of textchanged.

    select ename from tablename
    where ename like '%S%'

    Regards

    Sridhar Thota.
    If you learn't from defeat..
    You haven't really lost..

    Sridhar Thota.
    Editor: DNS Forum.

  • #761684
    Hai Gaurav,
    The drop down list is having the mode property through which you can choose it as 'dropdown' and then it will show the editable list.
    If you choose it as dropdown list then it will not show you the editable.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #761694
    Hello Gaurav,

    As per Sridhar said i am agreed with him. You can use TextChange event also :

    protected void ComboBox1_TextChanged(object sender, EventArgs e)
    {
    try
    {
    DataTable dt = new DataTable();
    con.Open();
    SqlDataAdapter sda = new SqlDataAdapter("SELECT StudentName FROM Student WHERE StudentName LIKE '" + ComboBox1.Text + "%" + "'", con);
    sda.Fill(dt);
    ComboBox1.DataSource = dt;
    ComboBox1.DataTextField = "StudentName";
    ComboBox1.DataValueField = "StudentName";
    ComboBox1.DataBind();
    }
    catch (Exception ex)
    {
    Response.Write(ex.StackTrace);
    }
    finally
    {
    con.Close();
    }
    }

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761723
    There is no such a ready made control available in application, With the help of jQuery / JavaScript and CSS you can make good editable dropdownlist
    see below links
    http://www.codeproject.com/Articles/30720/Ajax-ComboBox-in-ASP-NET
    http://www.codeproject.com/Articles/290218/Custom-ASP-NET-Editable-DropDownList

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #761724
    Basically you have to create the user control for this.

    You can try the following
    http://www.jeasyui.com/documentation/combobox.php

    By Nathan
    Direction is important than speed


Sign In to post your comments