I have no problem creating sql queries where the value for the parameter comes from a control (dropdownlist). However, how do i adjust my query and set up the dropdown list, so that when page first loads, no value is used as a parameter? For instance, say i was to create a gridview that filters by state. The dropdownlist contains a listing of states to filter by. However, lets say i wanted to include a value called “All States”, and have it be the default, and the gridfview show all states?
Share
Since you’re using the
SqlDataSourcecontrol; I think your best bet is to create a stored procedure and use that. You can then set a “default” parameter value, and set that to something like “All”. Then your stored procedure can do the logic behind figuring out how to craft the “WHERE”.AFAIK the
SqlDataSourcedoesn’t have the ability to change or omit parameters.EDIT
There is more information here about setting default values for the parameters. This is pretty straight forward.
As far as your stored procedure, you would want it to accept a parameter, probably a string, and it would then decide whether or not to use a
WHEREclause, similar to this: