I am seeing some peculiar WebDropDown behaviour with the latest version of the WebDropDown. I have 3 values when my page loads. The default selection is the second one. When I select value 3 and click a search button on my page causing a postback, the dropdown correctly shows the selected item/value #3. Then, when I go back and reselect value #2, the postback indicates the old selected item/value of #3, yet the ActiveItemIndex shows the correct index for #2. Is this a bug, or am I just missing something here?
I have confirmed by debugging on the client-side that both get_activeItemIndex() and get_selectedItemIndex() have values of 1 indicating that the second value in dropdown is selected. When I click a search button on my page immediately afterwards, dropdown.ActiveItemIndex = 1 and dropdown.SelectedItemIndex = 2.
Hello ,
I created a sample and tested it based on the information you provided and the behavior was as expected. The selected item index matched the active item index. Please test this sample and see if it works on your end. If it works as expected compare the sample against your application to see what is different.
If the sample doesn't work as expected please provide me more details about your environment so I can test again.
Thanks,
Valerie
If I call webdropdown.ClearSelection() after my value is used in each postback, SelectedValue correctly retains the current selection because dropdown.SelectedItems will always have only one index with one value. However, I still don't understand why I have to do this. Any ideas?
I do appreciate your help very much.
Hello,
I modified my sample to loop thru the selectedItems collection and the behavior appears as expected. Each time I postback the collection only has one item. Please look at the attached sample and test it again to see if the behavior is the same on your side. If so compare it to your application to see what is different. If possible modify the sample to demonstrate the behavior you are seeing so that I can be of further assistance.
Thanks,Valerie
Did you have a chance to test my sample?
We had the same problem. Thanks to the workaround of bgl3317 (clear selection), we could solve the issue.
Before the control was in an update panel and it worked properly but when we removed it from the update panel, it started behaving as bgl3317 explained.
I hope it will be fixed for next release.
Sandro
I've got a similar issue here. It happens when I'm using the "SelectionChanged" event of the WebDropDown as the trigger for an UpdatePannel that doesn't contains the WebDropdown itself.
To reproduce, just create a page with the following:
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
<ig:WebDropDown ID="WebDropDown1" runat="server" onselectionchanged="WebDropDown1_SelectionChanged" Width="200px"> <AutoPostBackFlags SelectionChanged="On" /> </ig:WebDropDown> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="WebDropDown1" EventName="SelectionChanged" /> </Triggers> </asp:UpdatePanel>
Then, in the code, add the following:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataSet testDataset = new DataSet();
DataTable testTable = testDataset.Tables.Add("TestTable"); testTable.Columns.Add("KeyValue", typeof(System.String)); testTable.Columns.Add("DisplayValue", typeof(System.String));
for (int i = 0; i < 10; i++) { DataRow newRow = testTable.NewRow();
newRow["KeyValue"] = i.ToString(); newRow["DisplayValue"] = string.Format("Item number {0}", i);
testTable.Rows.Add(newRow); }
WebDropDown1.DataSource = testTable; WebDropDown1.ValueField = "KeyValue"; WebDropDown1.TextField = "DisplayValue";
WebDropDown1.SelectedItemIndex = 0; } } protected void WebDropDown1_SelectionChanged(object sender, Infragistics.Web.UI.ListControls.DropDownSelectionChangedEventArgs e) { Label1.Text += "(SelectionChanged) : " + WebDropDown1.SelectedValue + "<br />"; }
The result is that when I change the selected item, the SelectedValue doesn't follow. Sometines it will "skip" values completely. Also, like bgl3317, I can see the items being added to the SelectedItems collection of the control.
Even using the ClearSelection orkaround, I still get another issue because the first item selected when the dropdown is first displayed will never cause the SelectionChanged Event to be triggered, even when the currently selected item is a different one.
Regards,
Eric B.