filtered query with dropdown control

S

Spartaco

I have a dropdown control into a page and a gridview, both are associated to
two SqlDataSource controls, one of them is used to fill the DropDownControl,
that is meant to be a filter over the query of the other SqlDatasource
associated to the grid. This works fine, whenever I choose an item in the
dropdown combo, I get a filtered grid.

I did this using the declarative syntax, without writing any code. ok, now I
want to put another item at the top of the combobox, to get an unfiltered
list, so the question is:

is there a fast way of doing this ? I could think about handling the
SelectedIndexChanged event of the combo to change the datasource of the grid
or the query used, but i would like to know if there was a more elegant and
faster way of doing this, with a declarative syntax, by using some unknown
property of the grid or datasource controls, or changing the select query.

thanks
 
G

Guest

Here's how I did mine....
On the dropdownlists databound event, use this:
DropDownList1.Items.Insert(0, "All Results...")
(or whatever you want the text to be. 0 is the zero based item index of the
control.)
Then on the ddl's selectedindexchanged event, check the value
IF ddl1.SelectedValue = "All Results..." THEN
SqlDataSource1.SelectCommand = "select * from table order by col1"
SqlDataSource1.DataBind()
ELSE
SqlDataSource1.SelectCommand = "select * from table where col2 = '" &
ddl1.selectedvalue & "' order by col1"
END IF

Also make sure autopostback is enabled for the ddl control.
 

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

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top