Last post Jul 11, 2017 12:00 PM by oned_gk
Jul 11, 2017 10:41 AM|Kvetch|LINK
I have a gridview binded to an sql data source.
the data source is select * from a where b=@b.
@b is gotten from a dropdownlist control.
But when the user selects "all" in the dropdownlist, how do I set the parameter value so that all items are shown?
So effectively the data source is now select* from a.
Thanks in advance
Jul 11, 2017 10:53 AM|PatriceSc|LINK
A common approach is to use a criteria such as :
WHERE b=@b OR @b IS NULL or
so that if you provide a NULL value for your criteria all rows are selected.
Jul 11, 2017 11:32 AM|asyed4u|LINK
WHERE b=@b OR @b IS NULL
<asp:DropDownList ID="DropDownList1" runat="server">
way :1 .....SelectCommand="SELECT ............FROM ............... where @b =-1 or databasecolumns = @b "
way :2 ........SelectCommand="SELECT ............FROM ............... where @b ='-1' or databasecolumns = @b "
Jul 11, 2017 12:00 PM|oned_gk|LINK
select * from a where (@b is null or b=@b)
above for first choice with empty value dropdown without defaultvalue in selectparameter
or in ddl databound event insert first choice Value="%" Text="Show All" for below query
select * from a where b like @b
for textbox set selectparameter defaultvalue="%"
or first dropdown zero value for below query, if b contain positive values
select * from a where (@b=0 or b=@b)