Select All (Any) From a DropDownList with range items in ASP.NET


SQL part:

Declare @length decimal(8,1)

SET

@length=9.5

SELECT

length FROM mylength

WHERE

@length

IS NULL Or

length

>=@length and length <

CASE

WHEN

@length= 7.5 THEN 8

WHEN

@length= 8.5 THEN 9

WHEN

@length= 9.5 THEN 10

WHEN

@length= 10.5 THEN 15

WHEN @length= 15.5 THEN 20

WHEN

@length= 20.5 THEN 25

WHEN

@length= 25.5 THEN 30

WHEN

@length= 30.5 THEN 35

WHEN

@length= 35.5 THEN 45

WHEN

@length= 45.5 THEN 60

WHEN

@length= 60.5 THEN 300

ELSE

1000.0

END

A complete sample ASP.NET page working with the DropDownList:
<asp:DropDownList ID="DropDownListLength" runat="server" AutoPostBack="true" >
<asp:ListItem Value="">Any</asp:ListItem>
<asp:ListItem Value="0.0">7" and under"</asp:ListItem>
<asp:ListItem Value="7.5">7.5" - 8"</asp:ListItem>
<asp:ListItem Value="8.5">8.5" - 9"</asp:ListItem>
<asp:ListItem Value="9.5">9.5" - 10"</asp:ListItem>
<asp:ListItem Value="10.5">10.5" - 15"</asp:ListItem>
<asp:ListItem Value="15.5">15.5" - 20"</asp:ListItem>
<asp:ListItem Value="20.5">20.5" - 25"</asp:ListItem>
<asp:ListItem Value="25.5">25.5" - 30"</asp:ListItem>
<asp:ListItem Value="30.5">30.5" - 35"</asp:ListItem>
<asp:ListItem Value="35.5">35.5" - 45"</asp:ListItem>
<asp:ListItem Value="45.5">45.5" - 60"</asp:ListItem>
<asp:ListItem Value="60.5">60.5" Plus</asp:ListItem>
</asp:DropDownList>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="id" HeaderText="id" SortExpression="id" />
                <asp:BoundField DataField="length" HeaderText="length" SortExpression="length" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:forumConnectionString %>" CancelSelectOnNullParameter="false"
            SelectCommand="SELECT [id], [length] FROM [myLength] WHERE  @length IS NULL Or (length >@length and length < CASE  WHEN @length= 7.5 THEN 8 WHEN @length= 8.5 THEN 9 WHEN @length= 9.5 THEN 10	WHEN @length= 10.5 THEN 15 WHEN @length= 15.5 THEN 20 WHEN @length= 20.5 THEN 25 WHEN @length= 25.5 THEN 30	WHEN @length= 30.5 THEN 35	WHEN @length= 35.5 THEN 45	WHEN @length= 45.5 THEN 60	WHEN @length= 60.5 THEN 300 ELSE 1000.0 END)">
            <SelectParameters>
            <asp:ControlParameter Name="length" ControlID="DropDownListLength" PropertyName="SelectedValue" Type="Decimal" />
            </SelectParameters></asp:SqlDataSource>
 
Question asked from here: http://forums.asp.net/p/1321016/2627669.aspx#2627669
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s