Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 December 21st, 2004, 08:20 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cast from type 'ListItem' to type 'Integer' is not

Hi

I'm trying to count how many items are checked in a listbox in ASP.NET (webform). I tried the following code:

    Dim index As Integer
    Dim counter as integer = 0
    For Each index In lstCustomers.Items()
        If lstCustomers.Items(index).Selected Then
             counter = counter + 1
        End If
    Next

I get the following exception: Cast from type 'ListItem' to type 'Integer' is not valid

What am I doing wrong? Could someone please help.

 
Old December 21st, 2004, 09:02 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I meant 'how many items are selected' instead of checked.

 
Old December 21st, 2004, 10:30 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Never mind I got it working.
->

    Dim li as Listindex

    For Each Li In lstCustomers.Items
        If Li.Selected Then
              counter = counter + 1
        End If
    Next








Similar Threads
Thread Thread Starter Forum Replies Last Post
integer data type in infopath vikram_vikram Other Programming Languages 0 November 29th, 2005 02:54 AM
Cast from string "" to type 'Integer' is not valid h3x SQL Server ASP 1 January 30th, 2005 09:35 PM
problem in cast of type yoord SQL Language 1 October 18th, 2004 03:19 PM
Have any function to check the integer type only calvinpost ASP.NET 1.x and 2.0 Application Design 2 April 1st, 2004 01:05 AM





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