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

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!
 
L

Lloyd Sheen

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
 
C

Cirene

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.)
 
L

Lloyd Sheen

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
 
C

Cirene

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
 
C

Cirene

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
 
E

Eliyahu Goldin

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
 
L

Larry Bud

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?
 
L

Larry Bud

I mean I would modify the sql to exclude the WHERE clause. I would remove
"where columnname=@ddvalue".

Kinda defeats the purpose of having a dropdown filter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top