Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to filter input of dropdownlist in web app?
Posted
Comments
Richard C Bishop 13-Feb-13 15:30pm    
The best answer you will get with a post like that is just some links to where that info already exists. So would it not be faster to just search it yourself?
mimtiyaz 13-Feb-13 15:32pm    
Hi..

You can try this link
http://www.dotnetcurry.com/ShowArticle.aspx?ID=408
mimtiyaz 13-Feb-13 15:38pm    
If this is the matter, then why there is a need to post this queries ?
behnamhaji 13-Feb-13 16:10pm    
we have a txtbox that user whit this It fills
Jibesh 13-Feb-13 16:13pm    
No offence to post queries but what richcb is trying to say here try to do some search in google and you may find this question is already answered.

we have seen a lot here that same question is answered many time, it just over populate the forum. so its always recommended to do a enough search before posting a query here.

1 solution

XML
<div>

        <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
            ontextchanged="TextBox1_TextChanged"></asp:TextBox>
        <br />
        <br />
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>

    </div>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Default4 : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        using (SqlConnection con = new SqlConnection("----"))
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("Select id,name FROM TEST WHERE name like '" + TextBox1.Text + "%'", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable DT = new DataTable();
            da.Fill(DT);
            DropDownList1.DataSource = DT;
            DropDownList1.DataTextField = "name";
            DropDownList1.DataValueField = "id";
            DropDownList1.DataBind();
            con.Close();
        }
    }
}
 
Share this answer
 

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