Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > BOOK: Beginning ASP.NET 4.5 : in C# and VB
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 19th, 2014, 02:57 AM
Registered User
Points: 26, Level: 1
Points: 26, Level: 1 Points: 26, Level: 1 Points: 26, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2013
Location: Arizona, USA
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default Filtering Data with a DropDownList (but not by default)

Hi Imar,

I just finished building the pages that are created in Chapter 13. I'm using the DropDownList control to limit the number of records returned for the GridView. All is working as it should. I wanted to ask you if instead of setting the default selection in the DropDownList to "Make a Selection" with a null value, if it would be relatively easy to change the default selection to "All Genres" and have the default value be an expression that returns all records. It seems that this would be easier with a string in which you could use a wild card (*) as the default value, but in this case as probably many, the key value/field is an integer. Do you have any thoughts on how I could approach this variation?

Perhaps a slightly different approach in a situation where there are a large number of records, would be to have no records returned by default, but include a selection in the DropDownList (the last option in the list) that returns all genres. Can you think of how to incorporate such an option?

Your thoughts and approach would be greatly appreciated.
Thank you
 
Old January 19th, 2014, 08:24 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Yes, you can do that, like this:

1. First, set CancelSelectOnNullParameter on the SqlDataSource to False so it still executes the query even if the GenreId parameter is null.

2. Then update the SQL statement to it queries all records when the @GenreId parameter is null:

Code:
SelectCommand="SELECT [Id], [Title], [Authorized], [CreateDateTime] FROM [Review] WHERE ([GenreId] = @GenreId OR @GenreId IS NULL)"
This way, when there is no selected Genre, .NET will pass null for @GenreId, causing all records to be returned.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
pmarti (January 19th, 2014)
 
Old January 19th, 2014, 01:31 PM
Registered User
Points: 26, Level: 1
Points: 26, Level: 1 Points: 26, Level: 1 Points: 26, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2013
Location: Arizona, USA
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Imar,

That is exactly they type of solutions I was hoping for. Thank you very much for providing the information on how to change that behavior. Without the approach you provided I would have written a lot of code in the code beside page checking for the selected value of the DropDownList control. I can't tell you how much I appreciate all the help you've provided as I stumble through relearning web development.
 
Old January 19th, 2014, 02:40 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome....

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!




Similar Threads
Thread Thread Starter Forum Replies Last Post
Filtering data Erik Severiens BOOK: Beginning ASP.NET 4 : in C# and VB 6 June 6th, 2013 11:21 AM
Filtering Data after its been cached Durkee VB.NET 2002/2003 Basics 0 November 13th, 2007 05:57 PM
data filtering from combobox MAKO C# 4 June 1st, 2006 03:54 AM
Filtering User data donydog Classic ASP Databases 0 February 6th, 2006 09:33 PM
Filtering data by code rodrigoss BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 June 23rd, 2004 02:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.