filtering from multiple dropdownlists
-
I have several DropDownList Controls (ddlOrder, ddlContact...) where the user may select multiple values and let the results be displayed in the datagrid. I know how to filter when chosing from any of these dropdownlists. But don't know how to filer if the user wants to filter based on selection of some of these dropdownlists at the same time? Any Help? Thanks. Here is my Code: Private sub myFilter() Dim objConn As SqlConnection Dim strSql As String strSql = "SELECT Company, Contact, Title, Phone " _ & "FROM Customers" objConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) Dim sdaCust As New SqlDataAdapter(strSql, objConn) Dim dstCust As New DataSet() sdaCust.Fill(dstCust, "Customers") Dim dtbCust As DataTable = dstCust.Tables(0) Dim dtvCust As New DataView(dtbCust) dtvCust.RowFilter = "Company = '" & ddlOrder.SelectedItem.Text & "'" dtvCust.Sort = "ContactName" dtgCust.DataSource = dtvCust dtgCust.DataBind() End Sub
-
I have several DropDownList Controls (ddlOrder, ddlContact...) where the user may select multiple values and let the results be displayed in the datagrid. I know how to filter when chosing from any of these dropdownlists. But don't know how to filer if the user wants to filter based on selection of some of these dropdownlists at the same time? Any Help? Thanks. Here is my Code: Private sub myFilter() Dim objConn As SqlConnection Dim strSql As String strSql = "SELECT Company, Contact, Title, Phone " _ & "FROM Customers" objConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) Dim sdaCust As New SqlDataAdapter(strSql, objConn) Dim dstCust As New DataSet() sdaCust.Fill(dstCust, "Customers") Dim dtbCust As DataTable = dstCust.Tables(0) Dim dtvCust As New DataView(dtbCust) dtvCust.RowFilter = "Company = '" & ddlOrder.SelectedItem.Text & "'" dtvCust.Sort = "ContactName" dtgCust.DataSource = dtvCust dtgCust.DataBind() End Sub
Hi there, You can create an expression based on the selection of the dropdownlists and assign to the RowFilter property. You can take a quick look at these to learn more: DataView.RowFilter Property[^] DataColumn.Expression Property[^]