Wrox Programmer Forums
|
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 June 18th, 2004, 02:44 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default Removing from a ListBox

I have an odd result trying to remove an individual item from a listbox.

Here's my one line of code:
Code:
lbxAttendee.Items.Remove(thisEvent.Tables("Attendees").Rows(i).Item("AttendeeType"))
I am using the "item as string" overload of the Remove method.

thisEvent.Tables("Attendees").Rows(i).Item("Attend eeType") returns a string value that matches an item text in the listbox. I have also tried CStr to cast the return value as a String.

At run time I get no errors, but the item is not removed from the listbox. Any ideas?


Thanks in advance for your comments.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old June 20th, 2004, 09:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

Are you rebinding the listbox everytime, first off? In not, can you verify that the entry returned is in the list (although this would probably return an error)?

Brian
 
Old June 21st, 2004, 12:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

if u get ur Data from DB its better to not retrieve them & not removing them later.

Always:),
Hovik Melkomian.
 
Old June 21st, 2004, 07:07 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am not rebinding the listbox on every postback. I use If Not Page.IsPostBack to do the initial load.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old June 21st, 2004, 07:32 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was able to solve the problem. Instead of removing a matching string value, I defined a new ListItem and removed that.

Dim thisItem As New ListItem
thisItem.Text = AttLabel.Text
thisItem.Value = thisEvent.Tables("Attendees").Rows(i).Item("Attend eeTypeID")
lbxAttendee.Items.Remove(thisItem)

This worked. I guess the overload for matching the string/text values isn't reliable.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.





Similar Threads
Thread Thread Starter Forum Replies Last Post
removing duplicates havey C# 9 February 26th, 2008 02:05 PM
multiple Listbox values in another listbox terryv Excel VBA 0 June 27th, 2007 07:01 AM
Removing items from ListBox on the client. DevelopWorld General .NET 1 July 26th, 2006 03:33 AM
Removing Read Only anukagni Access 5 June 13th, 2006 01:57 PM
I'm back :) Listbox var from listbox MichaelTJ .NET Web Services 2 October 21st, 2003 07:06 PM





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