[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Filter gridview based on drop down list

Posted on 2006-11-03
2
Medium Priority
?
348 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

829 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