Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 12th, 2004, 09:51 AM
Registered User
 
Join Date: Aug 2004
Location: Columbia, MO, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem Pre Selecting CheckBoxes in a CheckBoxLis

Hi,

I am very new to asp.net, and programming in general. I am workig on an application for my department's website in which I have a long list of checkboxes set up under a CheckBoxList control. I need to be able to preselect some of these checkboxes based on an array list of id numbers that is retrieved from the database.

I have been successful in setting up the array and created this loop to compare each check box item to each value in the array, if a match is found between the checkbox's value and a value in the array then I need to have the checkbox checked.

However, this is only working for the first value in the array. If I have 5 values in the array (55, 88, 89, 91, 94) only checkbox "55" is checked. Can anyone help me please! I've been banging my head against the wall for three days to get this far :)

Dim i As Integer
Dim j As Integer
Dim Found As Boolean

For i = 0 To CheckBoxList1.Items.Count-1
    For j = 0 To UBound(SpecSplit)
    If cint(SpecSplit(j)) = CheckBoxList1.Items(i).Value Then
        Found = True
    Exit For
    End IF
    Next

    If Found = True Then
    CheckBoxList1.Items(i).Selected = "True"
    Exit For
    End If
    Next


Thanks

Bret

Bret Sanders
  #2 (permalink)  
Old August 12th, 2004, 07:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You loop through the second array each time without setting it there, and the Found variable only affects one value. Try:

For i = 0 to CheckBoxList1.Items.Count -1
  For j = 0 to UBound(SpecSplit)
    'Items.Value is a String value, not an integer
    if (CheckBoxList1.Items(i).Value = SpecSplit(j).ToString()) Then
      'This is a boolean value, not a string
      CheckBoxList1.Items(i).Selected = True
      'should only exit the first for. If not, use a boolean variable to stop the looping
      exit for
    end if
  Next
Next

Try that, hope that helps,

Brian
  #3 (permalink)  
Old August 13th, 2004, 08:14 AM
Registered User
 
Join Date: Aug 2004
Location: Columbia, MO, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, that's exactly what I needed!

Bret Sanders
 


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
pre-selecting an item in a combo box kscase Visual Basic 2005 Basics 1 July 12th, 2007 07:33 AM
problem with submiting and checkboxes Paula222 Classic ASP Basics 3 October 30th, 2006 02:39 PM
problem with checkboxes with submittion Paula222 Classic ASP Basics 0 October 30th, 2006 12:42 PM
Problem with redistribution (Pre-requisites) larspersoon Visual Studio 2005 0 December 22nd, 2005 11:05 AM
problem with foreach loop in Checkboxes datagrid mbge9pjb .NET Framework 2.0 2 December 20th, 2005 10:03 AM



All times are GMT -4. The time now is 06:46 AM.


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