Solved

Filter gridview based on drop down list

Posted on 2006-11-03
2
338 Views
Last Modified: 2008-02-01
How would I filter a gridview based on a drop down list? I am not using object datasource or sql datasource.

'The dataset is generated based on the user's role
Me.gvRequests.DataSource = sr.GetRequests(CType(Session("Role"), Role))
Me.gvRequests.DataBind()

Public Function GetRequests(ByVal Role As Role) As DataSet
        Dim ad As New ActiveDirectory()
        Dim connection As New SqlConnection(ConnectionString())
        Dim sql As String = String.Empty
        Dim currentStatus As Integer = CInt(Status.Assigned)

        Select Case Role
            Case Role.MeManager
                sql = _
                        "SELECT DISTINCT TC_Requests.RequestNumber, " _
                      & "TC_Requests.RefNo, " _
                      & "TC_Requests.Originator, " _
                      & "TC_Requests.CreatedDate, " _
                      & "TC_Requests.CompletedDate, " _
                      & "(SELECT   TOP 1  Status " _
                      & "FROM TC_Routing " _
                      & "WHERE TC_Routing.RequestNumber = TC_Requests.RequestNumber " _
                      & "ORDER BY RoutingDate DESC) AS Status " _
                      & "FROM TC_Requests " _
                      & "INNER JOIN TC_Routing " _
                      & "ON TC_Requests.RequestNumber = TC_Routing.RequestNumber " _
                      & "ORDER BY TC_Requests.RequestNumber DESC"

            Case Role.ShopManager
                sql = _
                        "SELECT DISTINCT TC_Requests.RequestNumber, " _
                      & "TC_Requests.RefNo, " _
                      & "TC_Requests.Originator, " _
                      & "TC_Requests.CreatedDate, " _
                      & "TC_Requests.CompletedDate, " _
                      & "(SELECT   TOP 1  Status " _
                      & "FROM TC_Routing " _
                      & "WHERE TC_Routing.RequestNumber = TC_Requests.RequestNumber " _
                      & "ORDER BY RoutingDate DESC) AS Status " _
                      & "FROM TC_Requests " _
                      & "INNER JOIN TC_Routing " _
                      & "ON TC_Requests.RequestNumber = TC_Routing.RequestNumber " _
                      & "WHERE TC_Requests.Originator = '" & ad.GetNetworkLogon() & "' " _
                      & "ORDER BY TC_Requests.RequestNumber DESC"

            Case Role.MeEng
                sql = _
                        "SELECT DISTINCT TC_Requests.RequestNumber, " _
                      & "TC_Requests.RefNo, " _
                      & "TC_Requests.Originator, " _
                      & "TC_Requests.CreatedDate, " _
                      & "TC_Requests.CompletedDate, " _
                      & "(SELECT   TOP 1  Status " _
                      & "FROM TC_Routing " _
                      & "WHERE TC_Routing.RequestNumber = TC_Requests.RequestNumber " _
                      & "ORDER BY RoutingDate DESC) AS Status " _
                      & "FROM TC_Requests " _
                      & "INNER JOIN TC_Routing " _
                      & "ON TC_Requests.RequestNumber = TC_Routing.RequestNumber " _
                      & "WHERE TC_Routing.RoutedTo = '" & ad.GetNetworkLogon() & "' " _
                      & "AND TC_Routing.Status = " & currentStatus & " " _
                      & "ORDER BY TC_Requests.RequestNumber DESC"
        End Select

        Dim command As New SqlCommand(sql, connection)
        Dim da As New SqlDataAdapter(command)
        Dim ds As New DataSet

        Try
            da.Fill(ds, "dt_Requests")
            Return ds
        Catch ex As Exception
            Throw ex
        End Try

    End Function
0
Comment
Question by:JRockFL
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 17866570
You would do it by applying a RowFilter to a DataView based on your DataTable. Something like:

    Dim ds As DataSet = sr.GetRequests(CType(Session("Role"), Role))
    Dim dv As DataView = ds.Tables("dt_Requests").DefaultView
    dv.RowFilter = "YourColumn = '" & yourDropDown.SelectedText & "'"

    Me.gvRequests.DataSource = dv
    Me.gvRequests.DataBind()
0
 
LVL 8

Author Comment

by:JRockFL
ID: 17867169
perfect! thank you
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now