How to search data in gridview?

  • Thread starter Thread starter Jparv
  • Start date Start date
J

Jparv

Guest
Hello,

trying to search data in gridview When user enter firstname and Mobile no together or vice versa.

So first am loading the data table on button click after that am trying to enter first name and mobile no it gives the perfect result but when first I enter mobile no and than name its not filtering properly.Check the screen shot below
62ac5e75799fe1eb4933aece82283f8c._.png


private void btn_LoadTable_Click(object sender, EventArgs e)
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "select FirstName,LastName,MobileNo from CustomerDetails";
command.CommandText = query;
OleDbDataAdapter da = new OleDbDataAdapter(command);

da.Fill(dt);
dataGridView2.DataSource = dt;
connection.Close();


private void txt_SearchFirstName_TextChanged(object sender, EventArgs e)
{

DataView dv = new DataView(dt);
dv.RowFilter = string.Format("FirstName LIKE %{0}%", txt_SearchFirstName.Text.ToString());
dataGridView2.DataSource = dv;
}


private void txt_SearchMobile_TextChanged(object sender, EventArgs e)
{
DataView dv = new DataView(dt);
dv.RowFilter = string.Format("MobileNo LIKE %{0}%", txt_SearchMobile.Text.ToString());
dataGridView2.DataSource = dv;
}

Continue reading...
 
Back
Top