Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 16th, 2008, 06:18 PM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 124
Thanks: 0
Thanked 1 Time in 1 Post
Default CheckBoxList can not be Pre-loaded

I have coded a Sub btnSubmit_Click to insert the selected checkboxes of a ChecBoxList to the database table. Then in Sub Page_Load, I coded the following loop to set currentCheckBox selected = true whenever the currentCheckBox is not Nothing by Find the checkboxes By reading the "TestName" from the database.

After more a week's testing, I found out that the currentCheckBox was 'not Nothing' only when the TestNames were added manually to the database table. The TestNames inserted into the database table by the btnSubmit_click were Nothing and not selected as Checked.

I think the currentCheckBox, Nothing or not, was not activated by the btnSubmit_Click. More interesting, the database did show the TestNames added by btnSubmit_Click, but their currentCheckBoxes were not 'not Nothing' while the TestNames added manually were 'not Nothing'. Why? Something wrong with the FindByText code? I tried FindByValue -- same result. Any suggestions?

************************************************** ****
Do While objReader.Read()
   Dim currentCheckBox As ListItem = cblTests.Items.FindByValue(objReader("TestName").T oString())
   If currentCheckBox IsNot Nothing Then
     currentCheckBox.Selected = True
   End If
Loop
__________________
C. Jeffrey Wang
 
Old October 17th, 2008, 10:29 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well, this is happening because the Page_Load event is called first, and only after that the button_click event is called. So first time when page loads, there are no values in the database, but when you click the submit button, values are added into the database.

For trial, move the checkbox selection code in the btnSubmit_Click method, after you insert the records to the database.

Regards
Mike





Similar Threads
Thread Thread Starter Forum Replies Last Post
Checkboxlist epkgupta Visual Studio 2005 0 March 11th, 2008 05:31 AM
CheckBoxList stu9820 ASP.NET 1.0 and 1.1 Basics 10 May 25th, 2006 08:15 PM
How to get the value of pre? Edward King Javascript How-To 2 June 28th, 2005 07:38 AM
CheckBoxList eddiema VS.NET 2002/2003 1 April 9th, 2004 09:49 AM
pre-processing chenggong Crystal Reports 0 July 21st, 2003 09:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.