Try this. Hope it will help you.
txtName
is the search
TextBox
and
ddlSearch
is
DropDownList
for filtering
private void txtName_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(Connection.getConnectionString());
if (ddlSearch.Text == "Enter Name")
{
con.Open();
SqlDataAdapter adap = new SqlDataAdapter("select * from Item where Item_name like '" + txtName.Text + "%'", con);
SqlCommandBuilder build = new SqlCommandBuilder(adap);
DataSet ds = new DataSet();
adap.Fill(ds, "Items");
dataGridView1.DataSource = ds.Tables["Items"];
con.Close();
}
if (ddlSearch.Text == "Enter Item Code")
{
con.Open();
SqlDataAdapter adap = new SqlDataAdapter("select * from Item where Item_code like '" + txtName.Text + "%'", con);
SqlCommandBuilder build = new SqlCommandBuilder(adap);
DataSet ds = new DataSet();
adap.Fill(ds, "Items");
dataGridView1.DataSource = ds.Tables["Items"];
con.Close();
}
}
[Edit member="Tadit"]
Corrected formatting and grammatical issues.
[/Edit]