I have a WebDropDown "DDthisWeek" representing the week number of a year in my page and filled not from a datasource but only by Items 1 to 52.While loading the page in the preload event I set one item to be the selected item e.g. that item that the actual week represents. That works so far.But now if the user selects an other item in that DropDown the DDthisWeek_SelectionChanged is fired. Now in the code of this event handler I want to find out, which new value is selected and so I tried this:
Dim var = DDthisWeek.selectedValue
val idx = me.DDthisWeek.ActiveItemIndex
2. now using this to set the selection:
Me.DDthisWeek.Items(idx).Selected = True
3.no this has the expected value:
var = DDthisWeek.selectedValue
But this works only the first time! If I now select another Item, I get the correct ActiveItemIndex but line 3 gives me still the old value.How can I get the correct value after the user has selected an item.
my DropDowns code ist
<ig:WebDropDown ID="DDthisWeek" runat="server" Width="50px" AutoPostBack="False" AutoPostBackFlags-SelectionChanged="On"> <AutoPostBackFlags SelectionChanged="On" /> <Items> <ig:DropDownItem Key="01" Selected="False" Text="01" Value="01"> </ig:DropDownItem> <ig:DropDownItem Key="02" Selected="False" Text="02" Value="02"> </ig:DropDownItem> <ig:DropDownItem Key="03" Selected="False" Text="03" Value="03"> </ig:DropDownItem> ..... <ig:DropDownItem Key="50" Selected="False" Text="50" Value="50"> </ig:DropDownItem> <ig:DropDownItem Key="51" Selected="False" Text="51" Value="51"> </ig:DropDownItem> <ig:DropDownItem Key="52" Selected="False" Text="52" Value="52"> </ig:DropDownItem> </Items> </ig:WebDropDown>
Hello,
I have recreated a sample project following the pattern you describe here, but the behavior i'm experiencing is as expected. That is, upon changing the selection in the WebDropDown, the SelectedValue is adjusted to the current value of the WebDrowDown list. I've tested by changing the WebDrowDown value several times to verify correct behavior. If you send me your sample I will take a look to see what's happening.
Sincerely,TroyDeveloper Support Engineer
Ok. I created a sample showing this effect. Here I have one dropdown and this dropdown is set in the page_preload event to a value which is representing the actual week number of a year. Now try to select an other week number. The DDthisWeek_SelectionChanged event is fired and there the new selected value is expected. As you can see there in the first line (there is a breakpoint) the old value was recieved.
I am seeing the same thing. SelectedValue returns the old value.
I discovered an error in my code whereby I was actually referring at one point to the wrong control with a similar name. You might check that. SelectedValue now seems to be returning the correct value.
It is so easy to reproduce this behavior. I added a new example. Here is a dropdown on a page that has 52 items. If a selection is changed the event DDthisWeek_SelectionChanged is fired. In this event the first line is: Dim val1 = ddThisWeek.SelectedValue;
I expect that in a "changed" event the actual selected value is returned. In an "changing" event that may be differend.
Hi martinn,
I'm sorry. I did error here. But the solution is actually super easy. All you need to do is wrap your pre-load event code inside a: If Not IsPostBack Then.....End If. The problem was that at the pre-load event was continually interceeding and re-setting the SelectedValue back to '13'.
I hope this helps.
Opps, sorry that I didn't find that myself. I've corrected that and now it seems to work. But I still wonder why the value was always the last selected value. Hmm...never mind
Hi,
Please let me know if you have any further questions regarding this matter.