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.
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 cant 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.
Im not passing the value from the dropdown list properly, how do I do this?
This work because Im not passing a value.
Any help is appreciated, thanks.
- 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 cant 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.
Im 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 SubCode:
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 SubCode:
<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>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