the prodct table contains tha diffrent prodct with diff names..
for example tv --- which has tv codes prefix "tv" like tv1,tv2....& so on...
ipods has the prefix "ip"... ip1,ip2 ... & so on
this is my sqldatasource..:
|
in select query it will select all data from product ..
is there any way to filter the gridview at the runtime that means it change the select query of the sqlcommand (with where condition) ??
by taking the dropdown(which can contain values like "tv" which display only tv, ipods which dispay only ipods ... all will dispay all the products) or any other control??
Thanx!!

Kirtan PatelPosted Oct 26, 2009, 3:23 PM
Here is my example code
after you have bound the GridView to SqlDataSource just Change its Select command and rebind grid to Filter the records .
still i have included project files take a look to better understand :)
here is download link of sample i have coded for you
Download Project Files
protected void btnFilter_Click(object sender, EventArgs e)
{
if (txtFilter.Text != "")
{
SqlDataSource1.SelectCommand = "select * from Users where username ='" + txtFilter.Text.Trim() + "'";
GridView1.DataBind();
}
else
{
SqlDataSource1.SelectCommand = "select * from Users";
GridView1.DataBind();
}
}
protected void btnReload_Click(object sender, EventArgs e)
{
SqlDataSource1.SelectCommand = "select * from Users";
GridView1.DataBind();
}
check "Do you like this answer" if it helps you :)
Dipa AhujaPosted Oct 27, 2009, 11:56 AM