Gridview With Optional Parametric Query

I got gridview and populate it with Name,Departman,Location information BY choosing LocationID=@locationID and Departman=@departmanID but this time I wanna make those parameters optional so someone can search by just use departmanid and locationid information. How can I do that is there anyway to use that kind of queries by the way I am using strongly typed Datasets and writing queries in my DAL layer.
Thanks you in advance
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use a stored procedure and set the optional values or depending on the option values in stored procedure excecute respective query.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I've done something like this using a SqlDataSource.  First step was to set the DataSource's CancelSelectOnNullParameter="false".   Then use SQL ISNULL function in the SelectCommand like this:
SELECT * FROM myTable WHERE LocationID=ISNULL(@locationID, locationID) AND departmentID = ISNULL(@departmentID, departmentID)
In the ControlParameter I set ConvertEmptyStringToNull="True"  
You'll have to modify this a little, but you should be able to pass a null parameter to the DAL, and have it convert the null to a DBNull for the query.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.