as the title states I am trying to filter a grid view based on one or multiple selections made among 4 drop down lists. On a button click event I populate the grid view with the broadest set of information. From here I would like to have the grid view update as I make selections in the available drop down lists (4 in total).
While I feel like I could accomplish this through a series of if statements and a modified query for each condition, I feel like there should be a more efficient way this can be done. Below I have posted any pertinent code to this problem I am having.
html/asp code
<tr>
<td>
<asp:DropDownList ID="ddlSearchOCFamily" AutoPostBack="True" AppendDataBoundItems="True" DataTextField="FamilyLong" DataValueField="FamilyLong" runat="server"></asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlSearchOCRate" AutoPostBack="True" AppendDataBoundItems="True" DataTextField="RateLong" DataValueField="RateLong" runat="server"></asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlSearchOCTerm" AutoPostBack="True" AppendDataBoundItems="True" DataTextField="TermLong" DataValueField="TermLong" runat="server"></asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlSearchOCEnrollment" AutoPostBack="True" AppendDataBoundItems="True" DataTextField="TypeDescription" DataValueField="TypeDescription" runat="server"></asp:DropDownList>
</td>
</tr>
<tr>
<td>
<div style="overflow: auto; width: 100%; padding: 2px;">
<asp:GridView ID="gvReverseSearchOC" runat="server" Width="99%" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4" AutoGenerateColumns="False" PageSize="20" AutoGenerateSelectButton="True">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<SortedAscendingCellStyle BackColor="#FEFCEB" />
<SortedAscendingHeaderStyle BackColor="#AF0101" />
<SortedDescendingCellStyle BackColor="#F6F0C0" />
<SortedDescendingHeaderStyle BackColor="#7E0000" />
<Columns>
<asp:BoundField DataField="OrderCode" HeaderText="Order Code" SortExpression="OrderCode" Visible="True" ReadOnly="True" HeaderStyle-Wrap="False" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" ItemStyle-Wrap="False" />
<asp:BoundField DataField="Net Price" HeaderText="Net Price" SortExpression="Net Price" HeaderStyle-Wrap="False" />
</Columns>
</asp:GridView>
</div>
</td>
</tr>
page load event
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim RSQuery As String = "
SELECT dDown.OrderCode, dDown.[Description], dDown.[Net Price]
FROM (
SELECT SKU.OrderCode AS OrderCode, SKU.[Description] AS [Description],
(SELECT FORMAT(SKU.ListPrice * EnrollmentType.Multiplier, 'C')) AS [Net Price]
FROM Enrollment
INNER JOIN EnrollmentType ON Enrollment.EnrollmentTypeID = EnrollmentType.RecID
INNER JOIN SKU ON EnrollmentType.TypeID = SKU.EnrollmentTypeID
INNER JOIN SKUBuild ON SKU.SKU = SKUBuild.SKU
WHERE (Enrollment.AccountNumber = '12345')
AND (Enrollment.Active = 'yes')
AND (SKU.[Description] IS NOT NULL AND NOT (SKU.[Description] = '""'))
) AS dDown
"
pnlSearchOC.Visible = False
PopSearchOCDDLs()
PopGVSearchOC(RSQuery)
End Sub
Procedure to populate the gridview
Protected Sub PopGVSearchOC(ByVal query As String)
Dim dt As New DataTable
Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("WarrantyConnectionString").ToString)
Using cmd As New SqlCommand(query, con)
con.Open()
Using sdr As SqlDataReader = cmd.ExecuteReader
If sdr.HasRows Then
dt.Load(sdr)
With gvReverseSearchOC
.DataSource = dt
.DataBind()
con.Close()
End With
End If
End Using
End Using
If con.State <> ConnectionState.Closed Then
con.Close()
End If
End Using
End Sub
I have one more procedure that populates the drop down lists but I don't believe it is relevant to my problem, I may be wrong.
I am looking for an elegant solution to update/filter my grid view based on the selections made in the drop down lists, any information in this regard would be much appreciated. If I am missing any necessary code I would be happy to supply it but I am pretty sure its all here. Thanks for you time guys.
