ASP.NET requery DropDownList after filter?

Go To StackoverFlow.com

0

I have 2 DropDownListboxes. both are based on a SQLDataSource control. When the value of one is changed, it acts as a filter on the other. The event fires fine, I change the filter on the SQLDataSource, but the list in the second DropDownList doesn't change.

I have been looking for an answer to this for hours and it's frustrating me greatly. It seems like it should be something simple like a requery command. The code in question is below.

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
If Me.DropDownList1.SelectedValue > 0 Then
Me.SqlDataSource2.FilterExpression = "Arcft_Make_ID = " & Me.DropDownList1.SelectedValue
Else
Me.SqlDataSource2.FilterExpression = ""
End If
End Sub
2012-04-04 00:55
by Tom Collins
Have you explicitly called DataBind on the second dropdown after updating the FilterExpression? i.e., after your End If line, adding Me.DropDownList2.DataBind()Mike Guthrie 2012-04-04 01:00


0

If I'm not mistaken, you haven't really done anything by applying the FilterExpression. You still need to execute the query again. See the MSDN docs here. Relevant point at the top: "Gets or sets a filtering expression that is applied when the Select method is called.". So you need to call the Select method again.

2012-04-04 01:01
by Rob Lauer
Sorry it took me so long to reply, I figured I would get an email notice of replies.I was able to find the answer myself. I was able to find the answer myself. I would clear the list then databind it again. Not clearing it resulted in the new records being added to the drop down, instead of replacing them - Tom Collins 2012-04-05 16:25