Home All Groups Group Topic Archive Search About

multiple Rowfiltering and binding the changes to the datagrid

Author
31 Jan 2005 3:09 PM
Robert Gregory via DotNetMonster.com
I have the following problem: I have several DropDownList Controls where the user may select multiple values and let the results be displayed in the datagrid. The first filter will always work, but when the second filter is done, the effects of the first filtering are lost. So how do I make a filtering permanent, so that for the next filtering which is done the modified datatable is used?
Here my code:

Sub BindData(ByVal SelectedProduct As String, ByVal SelectedClient As String, ByVal SelectedSupplier As String, ByVal SelectedSalesman As String)
        Dim DSreporteorden As New DataSet
        Dim DTreporteorden As New DataTable
        Dim DAreporteorden As New SqlDataAdapter
        Dim view As New DataView
        view = Cache("reporteorden")
        If view Is Nothing Then
            ..setting up connection..
            ..querying the database and retrieving data..
            DAreporteorden.Fill(DSreporteorden)
            DTreporteorden = DSreporteorden.Tables(0)
            view = DTreporteorden.DefaultView
            Cache("reporteorden") = view
            objConn.Close()
        End If
        If SelectedProduct <> "All" Then
            view.RowFilter = "O_16 = '" & SelectedProduct & "'"
        End If
        If SelectedClient <> "All" Then
            view.RowFilter = "O_7 = '" & SelectedClient & "'"
        End If
        If SelectedSupplier <> "All" Then
            view.RowFilter = "O_6 = '" & SelectedSupplier & "'"
        End If
        If SelectedSalesman <> "All" Then
            view.RowFilter = "O_13 = '" & SelectedSalesman & "'"
        End If
        DGreporteorden.DataSource = view
        DGreporteorden.DataBind()
    End Sub

I would be grateful to receive a hint :-)

Regards,
Robert Gregory

--
Message posted via http://www.dotnetmonster.com

Author
31 Jan 2005 3:48 PM
Eliyahu Goldin
Robert,

I think you can make complex conditions with OR, AND and NOT operators.
Also, you always have an option of modifying the select statement according
to all filters.

Eliyahu

"Robert Gregory via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
message news:4267b5d7827440b98ff5d2ffe62eccac@DotNetMonster.com...
> I have the following problem: I have several DropDownList Controls where
the user may select multiple values and let the results be displayed in the
datagrid. The first filter will always work, but when the second filter is
done, the effects of the first filtering are lost. So how do I make a
filtering permanent, so that for the next filtering which is done the
modified datatable is used?
> Here my code:
>
> Sub BindData(ByVal SelectedProduct As String, ByVal SelectedClient As
String, ByVal SelectedSupplier As String, ByVal SelectedSalesman As String)
Show quoteHide quote
>         Dim DSreporteorden As New DataSet
>         Dim DTreporteorden As New DataTable
>         Dim DAreporteorden As New SqlDataAdapter
>         Dim view As New DataView
>         view = Cache("reporteorden")
>         If view Is Nothing Then
>             ..setting up connection..
>             ..querying the database and retrieving data..
>             DAreporteorden.Fill(DSreporteorden)
>             DTreporteorden = DSreporteorden.Tables(0)
>             view = DTreporteorden.DefaultView
>             Cache("reporteorden") = view
>             objConn.Close()
>         End If
>         If SelectedProduct <> "All" Then
>             view.RowFilter = "O_16 = '" & SelectedProduct & "'"
>         End If
>         If SelectedClient <> "All" Then
>             view.RowFilter = "O_7 = '" & SelectedClient & "'"
>         End If
>         If SelectedSupplier <> "All" Then
>             view.RowFilter = "O_6 = '" & SelectedSupplier & "'"
>         End If
>         If SelectedSalesman <> "All" Then
>             view.RowFilter = "O_13 = '" & SelectedSalesman & "'"
>         End If
>         DGreporteorden.DataSource = view
>         DGreporteorden.DataBind()
>     End Sub
>
> I would be grateful to receive a hint :-)
>
> Regards,
> Robert Gregory
>
> --
> Message posted via http://www.dotnetmonster.com
Author
31 Jan 2005 4:13 PM
Robert Gregory via DotNetMonster.com
Thanks for the remarks...BUT: If I use connectors like AND to combine the different rowfilter, I will have to write code for every possible combination. Why? Because the user has the choice to select something or not. 0 or 1 if you like. This corresponds to 2 out of 4 possible combinations. When I finally get my problem solved I want to add another 4 dropdownlist for the user to select. This will get to complicated. That's why I have to process one filter at a time and after each other...??? Any ideas???

--
Message posted via http://www.dotnetmonster.com
Author
31 Jan 2005 4:57 PM
Robert Gregory via DotNetMonster.com
THANKS a lot...in the end the idea was good, I tried it with AND and it worked :-)
Here the code, in case anybody wants to see an example.

Dim Filtro As String
        Filtro = " "
        If SelectedProduct <> "Todos" Then
            Filtro = "O_16 = '" & SelectedProduct & "'"
        End If
        If SelectedClient <> "Todos" Then
            If Filtro <> " " Then
                Filtro = Filtro & " AND O_7 = '" & SelectedClient & "'"
            Else
                Filtro = "O_7 = '" & SelectedClient & "'"
            End If
        End If
        If SelectedSupplier <> "Todos" Then
            If Filtro <> " " Then
                Filtro = Filtro & " AND O_6 = '" & SelectedSupplier & "'"
            Else
                Filtro = "O_6 = '" & SelectedSupplier & "'"
            End If
        End If
        If SelectedSalesman <> "Todos" Then
            If Filtro <> " " Then
                Filtro = Filtro & " AND O_13 = '" & SelectedSalesman & "'"
            Else
                Filtro = "O_13 = '" & SelectedSalesman & "'"
            End If
        End If
        If SelectedOrden <> "" Then
            If Filtro <> " " Then
                Filtro = Filtro & " AND O_3 = '" & SelectedOrden & "'"
            Else
                Filtro = "O_3 = '" & SelectedOrden & "'"
            End If
        End If
        If SelectedOrden_C <> "" Then
            If Filtro <> " " Then
                Filtro = Filtro & " AND O_4 = '" & SelectedOrden_C & "'"
            Else
                Filtro = "O_4 = '" & SelectedOrden_C & "'"
            End If
        End If

        view.RowFilter = Filtro

Regards,
Robert Gregory

--
Message posted via http://www.dotnetmonster.com