View Single Post
  #4 (permalink)  
Old February 24th, 2004, 03:37 PM
pjirelan pjirelan is offline
Registered User
 
Join Date: Feb 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the form class with code. Basically its loads a checkboxlist with 3 items and a submit button. The user selects items then hits the submit button. When I select items then hit submit the mycheck.Items(i).Selected is never true.

Public Class WebForm1
    Inherits System.Web.UI.Page

    Dim mytext As String
    Protected WithEvents CheckList As System.Web.UI.WebControls.CheckBoxList
    Protected WithEvents CheckListPlace As System.Web.UI.WebControls.PlaceHolder
    Protected WithEvents SubmitButton As System.Web.UI.WebControls.Button
    Protected WithEvents DebugLabel As System.Web.UI.WebControls.Label
    Dim count As Integer

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' CheckList.AutoPostBack = False
        CheckList.ID = "CheckList"
        CheckList.CellPadding = 2
        CheckList.CellSpacing = 2
        CheckList.RepeatDirection = RepeatDirection.Vertical
        CheckList.RepeatLayout = RepeatLayout.Table
        CheckList.TextAlign = TextAlign.Right

        If Not Page.IsPostBack Then
            CheckList.Items.Add(New ListItem("Item1"))
            CheckList.Items.Add(New ListItem("Item2"))
            CheckList.Items.Add(New ListItem("Item3"))
            CheckList.DataBind()
        End If

        SubmitButton.Text = "Fill Out Details"
        AddHandler SubmitButton.Click, AddressOf SubmitButton_Click
        If CheckList.Items.Count = 0 Then
            DebugLabel.Text = "NO ITEMS"
        End If
        CheckListPlace.Controls.Add(CheckList)

    End Sub

    Private Sub SubmitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ' Make sure a control was found.
        Dim sel As Integer
        Dim s As String
        Dim i As Integer
        Dim mycheck As CheckBoxList = _
                   CType(CheckListPlace.FindControl("CheckList"), CheckBoxList)

        If Not mycheck Is Nothing Then
            s = "Selected items:<br>"
            For i = 0 To mycheck.Items.Count - 1
                If mycheck.Items(i).Selected Then
                    s = s & mycheck.Items(i).Text & "<br>"
                End If
            Next i
            DebugLabel.Text = s
        End If
    End Sub
End Class