Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 688

Filter Grid View with 2 drop down menus

$
0
0
I have a simple gridview that needs to shows the facilities in our system. The Gridview also needs to be filtered by two dropdown menus.
  • Menu 1: facility type
  • Menu 2: facility status


I can get the gridview to bind on load and I can get the gridview to bind one dropdown menu after update control but I can’t get it to do both. I need to get it to filter on whichever dropdown menu is being selected, either by facility or by status.

I’m not passing the value from the dropdown list properly, how do I do this?
Code:

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged

        Dim srtfacType As String = Me.DropDownList1.SelectedValue

        If IsPostBack Then
            Me.GridView1.DataSource = sqlFacType
            Me.GridView1.DataBind()
        End If

        'If Me.DropDownList1.Text = facType Then
        'Me.GridView1.DataSource = SqlDataSource1
        'Me.GridView1.DataBind()
        'End If
    End Sub

Code:

Protected Sub DropDownList2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList2.SelectedIndexChanged
        Dim srtfacStatus As String = Me.DropDownList2.SelectedValue

        If IsPostBack Then
            Me.GridView1.DataSource = Sql
            Me.GridView1.DataBind()
        End If
    End Sub

Code:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"></asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HDOConnectionString %>" SelectCommand="SELECT DISTINCT [Facility_Name], [Facility_Type], [Location], [ContactPerson], [Status], [Phone], [City]  FROM [FacilityLocations] WHERE ([Facility_Type] = @Facility_Type) ORDER BY [Facility_Type]">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="Facility_Type" PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:HDOConnectionString %>" SelectCommand="SELECT DISTINCT [Facility_Name], [Facility_Type], [Location], [ContactPerson], [Status], [Phone], [City] FROM [FacilityLocations] ORDER BY [Facility_Name]"></asp:SqlDataSource>

This work because I’m not passing a value.
Code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
            Me.GridView1.DataSource = SqlDataSource2
            Me.GridView1.DataBind()
        End If
    End Sub

Any help is appreciated, thanks.

Viewing all articles
Browse latest Browse all 688

Trending Articles