frmSasp,
I use vb.net so you'll have to convert this, it's not usually too difficult.
Html code -
VB Code:
<TR vAlign="top">
<TD>Bound Checkbox List Example:</TD>
<TD><asp:CheckBoxList id="CheckBoxList1" runat="server"></asp:CheckBoxList></TD>
</TR>
CodeBehind -
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
' ... create your connection and dr etc. here
dr = myCmd.ExecuteReader()
Do While dr.Read()
With CheckBoxList1
.Items.Add(New ListItem(Convert.ToString(dr("OptionText")), Convert.ToString(dr("OptionValue"))))
End With
Loop
End If
End Sub
Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
Dim s As String = "Selected items:<br />"
Dim i As Int32
For i = 0 To CheckBoxList1.Items.Count - 1
If CheckBoxList1.Items(i).Selected Then
' List the selected items
s = s & CheckBoxList1.Items(i).Text
s = s & "<br />"
End If
Next
litMsg.Text = s
End Sub
Cheers Al