PC Review


Reply
Thread Tools Rate Thread

CheckboxList Problems

 
 
Michael Manuel via .NET 247
Guest
Posts: n/a
 
      20th Mar 2005
I seem to be having a lot of trouble using the CheckBoxList Control. I have created two pages to try and find out what I have been doing wrong. Both pages are causing me problems but different problems.

The page that I want to work will not display the selected items after clicking the button.

The page I created to try and locate the problem will display a duplicate set of items when loaded but displays the selected items. If I remove a some code from the Sub line it will not display to duplicate info. See code below.

Team.aspx.vb (Page I want to work)
Code Snippets

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'Team Details
'Skipped cookie Stuff

'Skipped DB Stuff

'Request for Join
strSQL = "Select tblMemberID from tblRequest where tblTeamID = " & TeamID.Rows(0)(0).ToString
Dim Reqs As New DataTable
Dim CheckReqs As New System.Data.OleDb.OleDbDataAdapter(strSQL, Conn)
CheckReqs.Fill(Reqs)

Dim i As Integer

For i = 0 To Reqs.Rows.Count - 1
strSQL = "Select UserName, FName, LName from tblMembers where tblMemberID = " & Reqs.Rows(i)(0)
Dim UserReq As New DataTable
Dim CheckUserReqs As New System.Data.OleDb.OleDbDataAdapter(strSQL, Conn)
CheckUserReqs.Fill(UserReq)

If UserReq.Rows.Count <> 0 Then
Dim lItem As New ListItem
lItem.Text = UserReq.Rows(0)(0) & "/" & UserReq.Rows(0)(1) & " " & UserReq.Rows(0)(2)
lItem.Value = Reqs.Rows(i)(0)
cbList.Items.Add(lItem)
End If
Next

End If
End Sub

Private Sub btnAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccept.Click
Dim i As Integer
For i = 0 To cbList.Items.Count - 1
If cbList.Items(i).Selected Then
lblMessage.Text &= cbList.Items(i).Text
End If
Next
End Sub

WebForm1.aspx.vb
Complete Code
'When "Handles MyBase.Load" is removed from the below line Duplicates do not show up
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 IsPostBack Then
Dim i As Integer
i = 1
checkboxlist1.Items.Clear()
For i = 1 To 6
Dim lItem As New ListItem
lItem.Text = "Item " & i
lItem.Value = i
checkboxlist1.Items.Add(lItem)
lItem = Nothing
Next
'End If

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Message.Text = "Selected Item(s):<br><br>"

' Iterate through the Items collection of the CheckBoxList
' control and display the selected items.
Dim i As Integer

For i = 0 To checkboxlist1.Items.Count - 1

If checkboxlist1.Items(i).Selected Then

Message.Text &= checkboxlist1.Items(i).Text & "<br>"

End If

Next

End Sub

If this was a double post please accept my apologies. Wasn't sure if it went through the first time.

--------------------------------
From: Michael Manuel

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>BoQbfV0eskKVCUISavFzdQ==</Id>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get Selected item in a Databinded CheckBoxList when CheckBoxlist is in a DataList? Patrick.O.Ige Microsoft ASP .NET 5 19th Jun 2005 07:11 AM
Problems on getting CheckBoxList selected Items luisg Microsoft C# .NET 3 20th Feb 2005 10:43 PM
Checkboxlist inside Repeater - doesn't fire click event for Checkboxlist JD Microsoft ASP .NET 3 16th Jun 2004 01:57 AM
problems with CheckBoxList Philip Townsend Microsoft ASP .NET 2 29th Jan 2004 06:53 PM
CheckBoxList Problems Philip Townsend Microsoft C# .NET 1 29th Jan 2004 06:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:12 PM.