tags:

views:

1725

answers:

3

Hi all,

out of curiosity, anyone knows the particulars of the internal implementation of ListControl.SelectedIndex = (int) VS ListControl.SelectedValue = .ToString()?

I'm having difficulties with a custom validation object we've built here to process all validation in one sweep.

I suspect using will raise a SelectedIndexChanged event, even though both the value and index remain the same, both before and after the operation.

(The ListControl's values are populated declaratively....)

As ever, thank you for your time!

A: 

The event SelectedIndexChanged should not be raised unless the user has changed the selected value/index and performed a postback.

SelectedIndexChanged is not going to be raised If you set the SelectedIndex or SelectedValue via code.

Torkel
A: 

Don't mean to sound obtuse, but it does! ;)

The value is programmatically set to the list, using ((ListControl)FindControl.("controlName")).SelectedValue = {stringValue}, and the SelectedIndexChanged event is raised, and caught by our delegate, thus invalidating the input.

Both the value and index are the same before and after the operation. The question is: is it possible that it changes during .Net's runtime operation of looking up the values to find the good one?

Pinpin
what's "the good one"?
Kon
The one where the Value property of the ListItem match the string passed to the SelectedValue property of the ListControl.
Pinpin
A: 

Hey,

The value of each ListItem within the RadioButtonList is suppoed to be unique, so SelectedValue represents that unique value. SelectedIndex represents the index of the item in the list regardless of text/value. SelectedIndexChanged only fires if the value actually changes.

Brian