• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

filter status by dropdownlist

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.
0
1jaws
Asked:
1jaws
2 Solutions
 
Ajay SharmaCommented:
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
0
 
Bob LearnedCommented:
You could use a DataView, with a RowFilter set to the condition from the DropDownList, and bind to the DataView.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now