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
Solved

Filter gridview based on drop down list

Posted on 2006-11-03
2
341 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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 this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

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