Hi everyone,
I have a question and I would greatly appreciate any help with it.

Here it goes:

I have a SQL Server Database that I am trying to display data to a data grid with. However, I have a drop down box and three radio buttons that will allow a user to filter the results that show up in the datagrid. I figured i could an if statement or a bunch of them. This is where my problem arises, I am looking to filter by numerous conditions(multiple select statements) and I am only able to specify one select statement in my SQL Datasource Wizard. Is there anyway I can manually write the code to query the database(maybe "SQLCommand") where i can also incorporate my conditional statements?

Any help is very much appreciated.


7 Years
Discussion Span
Last Post by daniel955

I do not use too much SqlDataSource but i believe you can do this

if (DropDownList1.SelectIndex > 0)  
    SqlDataSource1.FilterExpression = "FieldInYourDataSource = " + DropDownList1.SelectedItem.Value;
    SqlDataSource1.FilterExpression = null;

Try something like that. but if you really want to build your sql statement and query the database let me know, take in consideration that by doing that you lose some of the features provide by the sqldatasource control.



hi, is this what you are looking for?

My example:

using SQL datasource... configure data source ... specify SQL statement option

SELECT MemberID, Age, PositionID 
FROM Members 
WHERE Age = @Age AND PositionID = @PositionID

this SQL code will select member id with age of @Age and position id of @PositionID

@Age and @PositionID are parameters, which you will have to define the
id of the source(id of textbox, id of drop downlist .. etc).

Edited by daniel955: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.