need suggestions on dropdownlist with "ALL" item...

  • Thread starter Thread starter Cirene
  • Start date Start date
C

Cirene

I have a databound dropdownlist. It is acting as a "filter" for a gridview.
I wanted to add "ALL" to the first item on the list.

Question: In the SQLDataSource (that the ddl is bound to) how do you
suggest I handle the WHERE clause? If the ddl is set to "ALL" then I don't
really want to use the WHERE clause, but if it's something other than "ALL"
I do.

Your thoughts? How can I best implement this?

Thansk!
 
Cirene said:
I have a databound dropdownlist. It is acting as a "filter" for a
gridview. I wanted to add "ALL" to the first item on the list.

Question: In the SQLDataSource (that the ddl is bound to) how do you
suggest I handle the WHERE clause? If the ddl is set to "ALL" then I
don't really want to use the WHERE clause, but if it's something other
than "ALL" I do.

Your thoughts? How can I best implement this?

Thansk!

What you can do is handle the DataBound of the dropdownlist. I do this all
the time. Code sample below:

Protected Sub GenreList_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles GenreList.DataBound
GenreList.Items.Insert(0, New ListItem("All", "%"))
End Sub


Hope this helps
Lloyd Sheen
 
Great suggestion. Now, what's the best way to handle the WHERE clause? (If
it's "ALL" then there's really no need for the WHERE clause portion.)
 
Cirene said:
Great suggestion. Now, what's the best way to handle the WHERE clause?
(If it's "ALL" then there's really no need for the WHERE clause portion.)

In the example I gave the SQL is doing a like in the select where clause. I
use the value member of the selected item which for All is %. This give me
the "all" list. That might not work for you but I have seen SQL like this:

select * from mytable where mycolumn = @value or @value = 'All'

Hope this helps
Lloyd Sheen
 
Thanks Lloyd! Awesome...


Lloyd Sheen said:
In the example I gave the SQL is doing a like in the select where clause.
I use the value member of the selected item which for All is %. This give
me the "all" list. That might not work for you but I have seen SQL like
this:

select * from mytable where mycolumn = @value or @value = 'All'

Hope this helps
Lloyd Sheen
 
Would you filter the WHERE clause the same way as described when the user
selects "ALL" versus a "filter" item? (using the SQL Param)

Eliyahu Goldin said:
In 2.0 you can do the same without writing any code:

<asp:DropDownList id="GenreList" ... AppendDataBoundItems="true">
<asp:ListItem Value="%">ALL</asp:ListItem>
</asp:DropDownList>


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Lloyd Sheen said:
What you can do is handle the DataBound of the dropdownlist. I do this
all the time. Code sample below:

Protected Sub GenreList_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles GenreList.DataBound
GenreList.Items.Insert(0, New ListItem("All", "%"))
End Sub


Hope this helps
Lloyd Sheen
 
I wouldn't add WHERE clause for ALL in the first case. It is the simplest
solution.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Cirene said:
Would you filter the WHERE clause the same way as described when the user
selects "ALL" versus a "filter" item? (using the SQL Param)

Eliyahu Goldin said:
In 2.0 you can do the same without writing any code:

<asp:DropDownList id="GenreList" ... AppendDataBoundItems="true">
<asp:ListItem Value="%">ALL</asp:ListItem>
</asp:DropDownList>


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Lloyd Sheen said:
I have a databound dropdownlist. It is acting as a "filter" for a
gridview. I wanted to add "ALL" to the first item on the list.

Question: In the SQLDataSource (that the ddl is bound to) how do you
suggest I handle the WHERE clause? If the ddl is set to "ALL" then I
don't really want to use the WHERE clause, but if it's something other
than "ALL" I do.

Your thoughts? How can I best implement this?

Thansk!


What you can do is handle the DataBound of the dropdownlist. I do this
all the time. Code sample below:

Protected Sub GenreList_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles GenreList.DataBound
GenreList.Items.Insert(0, New ListItem("All", "%"))
End Sub


Hope this helps
Lloyd Sheen
 
I wouldn't add WHERE clause for ALL in the first case. It is the simplest
solution.

You have to. If your SQL data source says

where columnname=@ddvalue

What do you think will happen if @ddvalue is "all" or empty or any
value whatsoever?
 
Back
Top