filter dropdown
I want to have dropdown which bind from the database. It should have filter functionality such as if i write in textbox letter "S" then all item from "S" in drop down it will filter. so please help me out.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Aug 31, 2011, 7:18 AM
Here is a windows form solution for your questions?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace filter_dropdown
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
DataSet ds;
string str;
DataTable dt;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from student";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
while (reader.Read())
{
comboBox1.Items.Add(reader["sname"]);
}
reader.Close();
con.Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
comboBox1.Items.Clear();
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select sname from student where sname like '" + textBox1.Text + "%'";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
oledbda.Fill(ds, "student");
dt = ds.Tables["student"];
int i;
for (i = 0; i <= dt.Rows.Count - 1; i++)
{
comboBox1.Items.Add(dt.Rows[i].ItemArray[0]);
}
con.Close();
}
}
}
Thanks
If this post helps you mark it as answer
AjayPosted Aug 31, 2011, 6:07 AM
Amit ChoudharyPosted Aug 31, 2011, 5:59 AM
Is it a windows forms control, or Asp.net control or WPF etc.