Solved

Filter gridview based on drop down list

Posted on 2006-11-03
2
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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