Jump to content

Recommended Posts

Posted

I have a web page with a grid containing data filtered on a pull down selection. This works so long as I select a value, but I want to be able to leave the pulldown menu blank and have the filter return everything if the selection is NULL. I have configured the query and tested to make sure it works (which it does), but if I try this in the web page it doesn't display anything. I assume it is something to do with the NULL value? But after going round in circles I'm at a loss what to try next.

 

Can anyone explain to me what I should do in order to be able to have an option pulldown1 containing my filter but also include a blank option which will display all data please?

Posted
I have a web page with a grid containing data filtered on a pull down selection. This works so long as I select a value, but I want to be able to leave the pulldown menu blank and have the filter return everything if the selection is NULL. I have configured the query and tested to make sure it works (which it does), but if I try this in the web page it doesn't display anything. I assume it is something to do with the NULL value? But after going round in circles I'm at a loss what to try next.

 

Can anyone explain to me what I should do in order to be able to have an option pulldown1 containing my filter but also include a blank option which will display all data please?

 

Hard to help without seeing any code, but it depends on how you're forming your query. If I were to approach it, I'd probably have an if statement check the value of pulldown1, if it contains a value, pass that as an argument to your query, if it is null, I'd perform a different query to return everything...

 

e.g. (think of this as pseudo code, I'm not guaranteeing it would compile because I'm working from [poor] memory here!)

 

strQuery="SELECT * FROM table1";

if(pulldown1.Value!=null){
   strQuery += " WHERE column1=\"" & pulldown1.Value & "\"";

 

 

so you've got your query setup to return all values, unless a value is selected as a filter, then you add that filter to your query...

 

Of course that could be exactly what you are already doing :)

  • Thanks 1
Posted

Well I considered posting code, but it was within a bunch of other stuff. As I couldn't get it working I stipped it down to a basic pulldownMenu and grid with just test data just to see if I could get it working, but it seemed that whenever I tried to do something it didn't work. It actually got so bad at me going round in cicles I started dreaming about code over the wekend!!

 

I think I'll try it your way and see how I go....Thanks :)

Posted
C#. If I get time I'll have another look today. But I think I may change what I was doing. As I got stuck at the first hurdle, it kinda shows my programming skills :)
Posted
First thing that springs to mind: on your SqlDataSource object, check that the CancelSelectOnNullParameter property is set to False. The default is True.

 

Thankyou....this was what I was missing.

 

I knew it had to be something simple but for the life of me couldn't work out where.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...