[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Gridview With Optional Parametric Query

Posted on 2008-11-18
Medium Priority
Last Modified: 2012-05-05
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
Question by:mindcool

Accepted Solution

garavindbabu earned 750 total points
ID: 22992738
Use a stored procedure and set the optional values or depending on the option values in stored procedure excecute respective query.

Expert Comment

ID: 22993833
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.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question