Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design 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 October 4th, 2004, 02:20 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default ListBox Problem


Am dynamically filling a ListBox with values from backend.

Please go thro the following sample code:

ListBox1.Items.Add(New ListItem("text1", "value1"))
ListBox1.Items.Add(New ListItem("text2", "value2"))
ListBox1.Items.Add(New ListItem("text3", "value3"))

I select the third item and click on the button.
The problem is: as soon as i click on the button,
the selection is lost and the first item is
selected.

I dont get this problem on using:
ListBox1.Items.Add("text1")

But i need to have the value property to identify
each listitem separately.

PLEASE NOTE that i have set AutoPostBack of Listbox
to false and EnableViewState to true.

Can someone please tell me why this happens?

:) Spacy


 
Old October 17th, 2004, 03:49 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Can you provide more detail about how/when the add calls are running? Are you adding these to the list box every time or only on the first page hit (not ispostback)?
 
Old October 18th, 2004, 05:45 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Thanks a lot for replying planoie! Atlast a reply!

I have changed my logic to get rid of this problem. Am no longer
using: ListBox1.Items.Add(New ListItem("text1", "value1"))

But would still like to know why this is happening.
Well..am loading the listbox only in first page load
i.e. in !Page.IsPostBack

Thanks buddy!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox Problem Brendan Bartley Access 4 November 26th, 2007 01:34 PM
ListBox problem aliirfan84 ASP.NET 2.0 Professional 5 May 28th, 2007 08:39 AM
listbox problem faizee36 Access VBA 4 April 27th, 2006 09:58 AM
A ListBox problem csc820203 C# 6 June 15th, 2004 06:45 PM





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