473,499 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How dynamically add WHERE clause to sqldatasource

I have a gridview that is filtered by a databound dropdownlist. I've set
AppendDataBound to True and added the item "ALL" in the dropdownlist.

My gridview is supposed to be filtered by this dropdownlist.

When it's "ALL" I want to include everything. When it's something else I
want to filter the gv data by this dropdownlist.

Do I need to dynamically change the WHERE clause via code? I'm sure there's
an easier way to do this.

Please let me know....

Thanks!
Oct 23 '07 #1
2 3125
Do I need to dynamically change the WHERE clause via code? I'm sure
there's an easier way to do this.
Yes.
AFAIK, there's no other alternative.
Can do it in Page.Load event.
--
Cheers,
Gaurav Vaish
www.mastergaurav.com
www.edujini-labs.com
-------------------------------
Oct 23 '07 #2
On Oct 22, 8:19 pm, "Cirene" <invalid_em...@zzz.comwrote:
I have a gridview that is filtered by a databound dropdownlist. I've set
AppendDataBound to True and added the item "ALL" in the dropdownlist.

My gridview is supposed to be filtered by this dropdownlist.

When it's "ALL" I want to include everything. When it's something else I
want to filter the gv data by this dropdownlist.

Do I need to dynamically change the WHERE clause via code? I'm sure there's
an easier way to do this.
In your 'where' clause, add a parameter of @dropdown (or whatever you
want to call it)...

where (dropdown=@dropdown or @dropdown='All')

What I usually do is if your column that you're querying is an
integer, my default value for the dropdown will be 0 (zero), otherwise
I usually make it ALL or A.

Oct 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2033
by: Isoaxis | last post by:
On the page in question I have a gridview that displays the list of all products in the Products table of the DB. That gridview is bound with a sqldatasource using Visual Studio's "wizards". The...
6
8243
by: Dabbler | last post by:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to an SqlDataSource, then have a value from a boundfield in the row be passed as the keyfield for select where clause. Im...
0
3368
by: cyberbless | last post by:
I would like to dynamically assign a Select Statment to a a SqlDataSource. Problem is the SqlDataSource.Select() Command requires a "dataSourceSelectArgument" as one of its arguments. 1. What...
3
9225
by: dauphian | last post by:
Greetings, I have a user control, that I will need to display on a specific page based on the number of records in database: I have to query a site table to get the number of entries as well...
2
1979
by: djc | last post by:
1) I am wondering if I should be using an sqlDataSource object for my particular scenario. I need to loop through a listbox and perform an INSERT sql operation for each item. Could be a few or...
0
1610
by: jobs | last post by:
I have a gridview that times when selecting from specific table when I try to when I add a where clause. Even when I'm only seleting Top 1 which comes right back at the command line. I test the...
0
1842
by: rogoflap | last post by:
I have a SQLDatasource I created on a form. It is tied to the GridView on that form. I would like to dynamically change the SQLStatement based on some criteria on the form. It seems to...
1
7510
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
3
2524
by: Steven Edison | last post by:
I'm sure this will be a simple one... I have a SqlDataSource that I need a WHERE clause on it ONLY when the querystring contains "ProjectID", otherwise I don't need it. If you come to the...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.