Dynamically Populate a CheckBoxList in VB.Net





-2
Date Submitted Sat. Oct. 22nd, 2005 5:26 PM
Revision 1 of 1
Helper ses5909
Tags CheckBoxList | Selected | Values | VB.NET
Comments 1 comments
Dynamically Populate a CheckBoxList in VB.Net


'The function to bind the database data to your CheckBoxList Control
Protected Sub bindYourList()
     Dim objConn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("SqlServer"))
     Dim objCmd As SqlCommand = New SqlCommand("select description, id from notificationLists", objConn)
     objConn.Open
     cblList.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection)
     cblList.DataBind
End Sub
     

'
In the Page_Load function call your bind method.
bindYourList()


//in your aspx page make sure to declare your CheckBoxList and define the DataTextField and DataValueField parameters.
<asp:checkboxlist id="cblList" runat="server" DataTextField="description" DataValueField="id">

 

Sara Smith

www.ilovecode.com
Sara

ilovecode

Comments

Comments Selected Text
Mon. Oct. 8th, 2007 8:47 AM    Beginner Murugesan

Voting