I have a gridView control named dgvAllBikes. On form load i load dgvAllBikes. Now i want to filter this gridView which is dgvAllBikes on basis of three options and a search button.
1) CC
2) Model
3) Color
When i click on search button i want to filter dgvAllBikes on basis of these three options.
Here is my LoadGrid Code
private DataTable LoadGrid()
{
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("spGetAllBikes", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader r = cmd.ExecuteReader();
dtAllBike = new DataTable();
dtAllBike.Load(r);
}
return dtAllBike;
}
i have declared DataTable in class level
string CS;
protected DataTable dtAllBike;
public SaleBike()
{
InitializeComponent();
CS = ConfigurationManager.ConnectionStrings["BikeDB"].ConnectionString;
}
Here is the code for btnSearch.
private void btnSearch_Click(object sender, EventArgs e)
{
BindingSource bs = new BindingSource();
bs.DataSource = dgvAllBikeDetails.DataSource;
bs.Filter = dgvAllBikeDetails.Columns["CC"].HeaderText.ToString() + " LIKE '%" + tbCCSearch.Text + "%'";
dgvAllBikeDetails.DataSource = bs;
It filter on basis of CC but i am not able to bind the other two option. Your help will be really appreciated.