views:

25

answers:

1

I am trying to populate an (editable) gridview in ASP.NET with a table from SQL. I have a SQLDataSource set up for this. I also need to have this gridview be filterable based on parameters entered in textboxes. I have tried using ControlParameters for this and it works but the problem there is when all textboxes are empty I want it to display all results in the gridview. What it does is display nothing because no entries have parameters that equal "". Is there an easy way to do this that I am missing or is there a better way to go about it other than a SQLDataSource?

A: 

I think I got it working. In case anybody else is wondering here is what I had to do. First I needed to modify my select statement within the SQLDataSource a little bit from

SELECT * FROM [MyTable] WHERE ([ColumnName] = @Param1)

to

SELECT * FROM [MyTable] WHERE (@Param1 IS NULL OR [ColumnName] = @Param1).

Then I set the parameter for the SQLDataSource: CancelSelectOnNullParameter="False".

novacara
@novacara You can also use the ConvertEmptyStringToNull attribute in your ControlParameters so that it will pass NULL down to SQL when an individual parameter is empty.
PhilPursglove