Ghsotwalker42
Ghsotwalker42

Reputation: 143

Error with Asp.net checkbox list

Im having a problem with my checkbox list. I'm able to loop though it, but I can not seem to find that items are checked. Im coding this in VB.net 2010 and asp.net In my for each i always get False on selected.

Here is some of my code:

Protected Sub cmdSend_Click(sender As Object, e As System.EventArgs) Handles cmdSend.Click
    'Check for checked users. 
    Dim lqText As New lqAlarmAndGoDataContext

    Try
        For Each foundCheckedUser In cbMembers.Items
            If foundCheckedUser.Selected Then
                Dim objText As New tbTxtMessageQueue
                With objText
                    .TxtFrom = "[email protected]"
                    .TxtTo = foundCheckedUser.value
                    .TxtBoddy = tbMessage.Text
                    .SentFlag = False
                End With
                lqText.tbTxtMessageQueues.InsertOnSubmit(objText)
                lqText.SubmitChanges()
            End If
          Next
    Catch ex As Exception

    End Try


End Sub

Upvotes: 0

Views: 296

Answers (2)

the_lotus
the_lotus

Reputation: 12748

Where do you bind your data to the checkbox?

Make sure it's not being rebinded before the button onclick by using

If Page.IsPostBack Then

Also, make sure your viewstate are enabled

Upvotes: 2

Ann L.
Ann L.

Reputation: 13975

Are you rebinding cbMembers on each postback? That will cause your selection info to be lost. Try refactoring your code so that cbMembers only gets bound once.

Upvotes: 2

Related Questions