Home DotNet Easily Populate CheckListBox From a DataSource
Author:

You could easily populate a CheckListBox from a data source such as from SQL Server or from Oracle instead of populating the check items manually. Here's an example:

Create the tag on the ASPX page:

<asp:checkboxlist id="cblMyGroup" RepeatColumns="2" repeatlayout="flow" runat="server"  RepeatDirection="Horizontal" width="700px">

</asp:checkboxlist>

 

In The Code Behind Page:

 

 

    Protected Sub LoadTOG()

 

        Dim myConnection As SqlConnection = New SqlConnection("Data Source=yourSQLServer; Initial Catalog=yourDB; Integrated Security=SSPI;")

        Dim SelectCmdString As String = "select * from MyGroup"

        Dim mySqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(SelectCmdString, myConnection)

 

        Dim dsMygroup As DataSet = New DataSet()

        mySqlDataAdapter.Fill(dsMygroup, "Mygroup")

 

        cblMyGroup.DataSource = dsMygroup

        cblMyGroup.DataValueField = "group_ID"

        cblMyGroup.DataTextField = "Title"

        cblMyGroup.DataBind()

 

    End Sub

 



Comments (0)
Write comment
Your Contact Details:
Comment:
Security
Please input the anti-spam code that you can read in the image.

"