Processing optional request parameters

I have a GridView associated with a DataSource request with parameters related to controls.

What is the standard / best way to handle optional request parameters?

+3
source share
2 answers

Something like .. set the control parameter to -1, then in your request do something like ...

Select * From Blah Where
(Somefield = @param or @param = -1)
+5
source

On your DataSource, use ControlParam for the DefaultValue parameter:

<asp:ControlParameter Name="CustomerID" 
    ControlID="DropDownList1" PropertyName="SelectedValue"  
    DefaultValue="-1" />

Then in your SQL query, check this default value from your ControlParameter:

 SELECT * 
 FROM Invoices
 WHERE (CustomerID = @CustomerID OR @CustomerID = -1)
+3
source

Source: https://habr.com/ru/post/1740533/


All Articles