Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
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 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 August 12th, 2004, 09:51 AM
Registered User
 
Join Date: Aug 2004
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
 
Old August 12th, 2004, 07:27 PM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old August 13th, 2004, 08:14 AM
Registered User
 
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, that's exactly what I needed!

Bret Sanders





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





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