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.
Hi,
I have stepped through your sample and it actually looks to be working correctly. By that I mean, I'm getting the correct values for ActiveItemIndex, CurrentValue, SelectedValue, SelectedItemIndex, etc, after each pass through test. So, it looks to be worked as expected.
Is there a chance that you are taking note of the SelectedValue before completely stepping through the code? If you haven't stepped through to the point of passing in the index of the new selection into the control, you won't be able to see the SelectedValue reflect the current selection.
I hope this helps. Please let me know if you have any additonal questions.
I don't know what to say about this answer. May be that you are recieving the correct values, but I can not understand this. How can it be that I can reproduce this error every time I want it to do and you can't see any error?
As I wrote in the last post, I have set a brakepoint in the DDthisWeek_SelectionChanged event and there I definitely get the wrong (the last selected) value at that point. I'm using Visual Studion 2010 and the Infragistics .NetAdvantage Version is 10.3.20103.2105.And I still have this behavior and I thought that my example show it clearly. I have just verified that I have send the correct sample.
Please let me know if you have any further questions regarding this matter.
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 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.
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.
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.