?
Solved

Filter gridview based on drop down list

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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 …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 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