Filtering Datagrid Rows Multiple Times

K

KJ

I have a datagrid in which I filter on what is selected in a
dropdownlist.
It filters correctly, but when I select the value to take it back to
it's original state. I set the datasource to the original datatable
and nothing happens. My code is below:

Private Sub ddl1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ddlVendorSummary.SelectedIndexChanged
Dim strShortName() As String
Dim dv As DataView

m_dt = DirectCast(Session("dt"), DataTable)
strShortName = Split(ddl1.SelectedItem.Value, "-")
If UBound(strShortName) = 1 Then 'If a filter is selected

dv = m_dt.DefaultView
dv.RowFilter = "ShortName = '" & strShortName(0) & "'"
With dgNames

.DataSource = dv
.DataBind()
End With
Else 'If "ALL" is selected in the dropdownlist

With dgNames

.DataSource = m_dt
.DataBind()
End With
End If
End Sub
 
B

Branimir Giurov

Hi KJ,
why don't you try to set the RowFilter to an empry string - should work OK.
something like:

Private Sub ddl1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ddlVendorSummary.SelectedIndexChanged
Dim strShortName() As String
Dim dv As DataView

m_dt = DirectCast(Session("dt"), DataTable)
strShortName = Split(ddl1.SelectedItem.Value, "-")

dv = m_dt.DefaultView
dgNames.DataSource = dv

If UBound(strShortName) = 1 Then 'If a filter is selected
dv.RowFilter = "ShortName = '" & strShortName(0) & "'"
Else 'If "ALL" is selected in the dropdownlist
dv.RowFilter =""
End If

dgNames.DataBind()

End Sub

good luck :)
Branimir
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top