ddPersonList.SelectedValue gave me the valuefield of the selected item (autopostbackflags is set to on). Since upgrading to 10.1 i get a null reference exeption.
When stepping the code ddpersonlist.SelectedItemIndex gave me 358 (correct) but still the selectedvalue is null reference.
What happened? Help (quick!) is appreciated!
Hi,
I cannot determine what's the cause of this issue without looking at some code (ASPX + code behind). That would help me a lot in resolving it.
Thank you,
Angel
Can anyone help? I'm totally stuck and getting frustrated.
Hello Lisa,
I've researched your sample. In order to overcome this issue I would suggest provide a datasource on each postback without databind. the WebDropDown control does not keep its data items in viewstate and this requires datasource to be provided on each postback. To invoke dataBind() is not needed at all. I see in your code that you bind the WebDropDown on firs postback only and then if not postback you are trying to access a value form webdropdown item. which is not there since datasoruce is not provided . You can use ItemSelectedIndex to determine which item has been selected on previous round-trip to the client like this:
ddPersonList.SelectedItemIndex
Hope this helps you.
Let me know if you have any questions.
Thank you for your reply.
SelectedItemIndex only gives me the index... I need the value of the item chosen, the index does me no good really. With or without the DataBind() (and removing the if postpack line), I get the same results. I get a correct value for SelectedItemIndex but SelectedValue gives me a null reference error.
Hey,
You can refer to the following thread, it discusses the same issue. We are going to fix it for the next service release. In the meantime you can use the workaround suggested in my last post in this thread:
http://forums.infragistics.com/forums/t/34601.aspx
Thanks,
I will check this out and let you know asap. By the way, if the first item is already selected, selection won't be changed (events also won't fire because we are selecting the same item again).
When I use the typeahead, here is what it's doing.
If I type ahead and say 2 items show up in the list: if I pick the first item, the text I had typed remains in the dropdown instead of the item I selected. If I select anything OTHER than the first item, the item then properly shows up in the list. If I then go select the first item, it shows up fine. But if the very first time I select the first item in the list, it will not then replace the text in the dropdown.
For the record, before the update I did not have the ispostback code in there. Someone here said I needed that and I see, thanks to your explanation why I do not.
Ok I have done what you suggested and part of it is working again (I have also upgraded to 10.2.
The part still not working, if I use the type ahead so it filters the list, and then select an item from the filtered list, it does not put the value in the dropdown when it collapses (my filtered text I had typed shows up still) and it does not run the update panel.
On one hand, you have a good point that this was working before. But it wasn't working properly , so the new behavior you are seeing is caused by this fix. The issue was that if i set a data source, and then change the data source to some completely different data source, the selected index and selected value weren't necessarily reset. What could happen is that if my new data source has less items, my index can be now out of range, or even worse, it can be in range, but point to the wrong item.
In fact, the microsoft dropdownlist control behaves in the same way as the WebDropDown is currently behaving. If the control is bound to a data source object, it requires its data source to be set every time in code behind, otherwise data items will not be persisted.
As a workaround, you can get save the Selected Index in some variable (SelectedItemIndex)., then call DataBind(), and then just get the item's value by index, provided you have stored the actual index:
int selectedIndex = dropDown.SelectedItemIndex;
dropDown.DataBind();
dropDown.Items[selectedIndex].Value; // that's the desired SelectedValue
again, the MS asp:DropDownList behaves in the same way.
Hope it helps,