Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 16th, 2008, 06:18 PM
Friend of Wrox
Points: 630, Level: 9
Points: 630, Level: 9 Points: 630, Level: 9 Points: 630, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Austin, TX, USA.
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
Reply With Quote
  #2 (permalink)  
Old October 17th, 2008, 10:29 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:24 PM.


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