filtering from multiple dropdownlists

V

viktor9990

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)
'" & ddlOrdr.SelectedItem.Text & "'"

dtvCust.RowFilter = "Company = '" & ddlOrder.SelectedItem.Text & "'"
dtvCust.Sort = "ContactName"
dtgCust.DataSource = dtvCust
dtgCust.DataBind()
End Sub
 
E

Elton W

Hi Viktor

You can use

dtvCust.RowFilter = "Company = '" &
ddlOrder.SelectedItem.Text & "' AND ContactName = '" &
ddlContactSelectedItem.Text & "'"

HTH

Elton Wang
(e-mail address removed)

-----Original Message-----
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)
'" & ddlOrdr.SelectedItem.Text & "'"

dtvCust.RowFilter = "Company = '" &
ddlOrder.SelectedItem.Text & "'"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top