filter status by dropdownlist

1jaws
1jaws used Ask the Experts™
on
I have a table that has tblcheck for active for true false in database sql server. I need to add a dropdown  that will only show actives my default on page load, dropdown will have active and inactive. so, basically on page load i will see all actives from database which value = true. how can i do that on c# on web dev.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
what i got from your question that, you want to show database column values in a dropdownlist where some value is defined as  true.

So lets assume the the column u want to show is cActivity and status column's name is cStatus.


    Dim myConnection As SqlConnection
    Dim oblV As New vbGlobalMethods
    Dim connStr As String = "your connection string goes here"

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

    If Page.IsPostBack = False Then
                fillCmbCity()
    Else

End Sub


Private Sub fillCmbCity()

        cmbActivity.Items.Clear()
        cmbActivity.Items.Add("")

        Try
            Dim dr As SqlDataReader
            Dim comm As SqlCommand
            myConnection = New SqlConnection(ConnStr)
            myConnection.Open()
            Dim sql As String
            sql = "select cActivity from tblActivity where cStatus='true' order by uCityName asc"
            comm = New SqlCommand(sql, myConnection)
            dr = comm.ExecuteReader
            While dr.Read
                cmbActivity.Items.Add(dr.Item("cActivity"))
            End While
            dr.Close()
            myConnection.Close()
        Catch ex As Exception
            lblMessage.Text = ex.Message

        End Try
    End Sub
Most Valuable Expert 2012
Top Expert 2008
Commented:
You could use a DataView, with a RowFilter set to the condition from the DropDownList, and bind to the DataView.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial