Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 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 September 9th, 2003, 07:28 PM
Registered User
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default SelectedIndexChange uses ListItem value

I have a dropdown box with code in the SelectedIndexChanged event. However, the event does not fire on every change because the index value takes the value of the listitem. Why is this? Can someone please shed some light on why this is happening. To offer more insight, I have about 20 items, half of them have a value of 1, the other half have a value of 0. I add them to dropdown by setting a dataset table as the dropdown data source.
 
Old September 10th, 2003, 10:47 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Consider this...
<select name="mySelect">
    <option value="1">One</option>
    <option value="1">Two</option>
    <option value="2">Three</option>
    <option value="2">Four</option>
</select>
You select "One" and post. Request.Form("mySelect") = 1
You select "Two" and post. Request.Form("mySelect") = 1
If mySelect.LastValue <> mySelect.CurrentValue Then
    Fire off SelectedIndexChanged event.
End If
How does it know the difference?

The selected index value does not come from listitem.value, it's figured out based on what the listitem values are in the sequence stored in viewstate. If there are duplicate list values you'll only see a a change when you switch to an item that actually has a different value and at that the selected item will be the first item to have that value. All listitems must have a unique value.

Peter
 
Old September 10th, 2003, 07:04 PM
Registered User
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx Pete. You confirmed exactly what i thought, which by the way is terrible. I also appreciate your code sample, however, i think when i bind the dataset to the dropdrown, i will use an incremental value to append to the value of the list item, and take off the appendage when i need to.

Thanx again for the quick response.
 
Old September 11th, 2003, 09:33 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Is there a reason that you don't have unique values? That's kind of the point of the value attribute. The text part of the select option is just for the human's. If the text part of your listitem is also the value that you are eventually going to use, you could just set the value attribute of the listitem to the same field in your databind settings.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing ListItem objects Andrew.Berry ASP.NET 2.0 Professional 1 April 8th, 2008 12:25 PM
DropDownList-SelectedIndexChange(Plz Help) dagad ASP.NET 2.0 Basics 8 November 6th, 2006 01:40 AM
DropDownList-SelectedIndexChange(Plz Help) dagad ASP.NET 2.0 Professional 3 October 27th, 2006 08:13 AM
listitem alyeng2000 ASP.NET 1.0 and 1.1 Basics 2 January 3rd, 2004 10:13 AM





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