Last post Jul 27, 2012 10:31 PM by subhash.sheladia
Jul 26, 2012 12:58 PM|sellsb|LINK
I have tried this so many ways and can't get anywhere.
i have a sqldatasource that am filtering with 2 dropdownlists. i also tried to do with select where parameters.
select * from table
filter expression= id=id or place=place
long story short i can successfully filter by only having one control but as soon as i add the second it no loner filters.
i know it is in the statement but i want them to filter independantly, ie if both are null show all records, if id value selected filter by it alone, hence the or statement.
i would really appreciate any and all help.
Jul 27, 2012 10:20 PM|Decker Dong - MSFT|LINK
i know it is in the statement but i want them to filter independantly
As far as I see, I think you can just generate different kinds of sql statement when choosing different kinds of values in the Dropdownlist when clicking the button——
//In the button's click……
using(SqlDataAdapter adapter = new SqlDataAdapter("","Your conn str"))
string sql ="select * from xxx";
if(Dropdownlist1.SelectedValue!=null && Dropdownlist2.SelectedValue!=null)
sql+=" where (id=@id) or (place=@place)";
DataTable dt = new DataTable();
Jul 27, 2012 10:31 PM|subhash.sheladia|LINK
Prepare your sql query dynamic ...Suppose
string sqlQuery=" Select * from Employee where 1=1";
sqlQuery +=" and id=@id";
sqlQuery +=" and place=@place";