Hi,
There is many way to filter the data when you click the button with the text box value .
Here i m giving two simple way.
1 . Store the data In session variable when you bind the data at first time
after clicking on the button i.e "filter" retrieve the data from session and add the following code.
//first store data in "SessionVerible " as "storedata"
Dataset ds= (Dataset)session("storedata") // Casting the data from session to dataset
// now in ds you will get all data which is already binded in GridView
gridView1.DataSource = ds.Tables["Products"].Select("Name = '" + text-box value/Filter value +"'");
gridView1.DataBind();
//In select statement you can the apply the filter as per your criteria.
2. Second Method when you click on the button then recall the following code with your filter criteria
string connStr =WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
string sqlProducts = "SELECT ProductID, ProductName, UnitPrice FROM Products WHERE ProductName ='"+ text-box value/Filter value+"'";
SqlDataAdapter da = new SqlDataAdapter(sqlProducts, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Products");
gridView1.DataSource = ds.Tables["Products"];
gridView1.DataBind();
Thanks and regards,
Sushilkumar Shinde
Sushilkumar Shinde
Arjunan_Csharp, if this helps please login to Mark As Answer. | Alert Moderator