Hello again....
I have a a WebDropdown that has been loaded with data from a table. What are the properties that I need to use to get and restore the selected item in the WebDropdown.
Hi,
The selected item is automatically stored in the SelectedItem WebDropDown property. If you have EnableMultipleSelection=true, you need to use the SelectedItems collection :
1)
WebDropDown1.SelectedItem
2)
WebDropDown1.SelectedItems
You do not need any special code / logic to store and restore the selection across postbacks - it is done automatically.
In order to set an Item as selected, you can do :
WebDropDown1.Items[0].Selected = true; // this will mark the first item as selected
For single selection you can also do :
WebDropDown1.SelectedItem = item;
Thanks,
Angel
Here is the code for th control. I still cant get it to restore the selected item from the saved value field that was saved in the database. I was Using WebCombo. I used [ControlName].DataValue to get the IRecId and [ControlName].FindByValue([Var int32]).Selected = True to restore the IRecId data. These properties are not in WebDropDown.
<ig:WebDropDown ID="IndustryDdl2" runat="server" AutoFilterResultSize="30" AutoFilterSortOrder="Ascending" DataKeyFields="IRecId" DataSourceID="dsIndustries" DropDownAnimationType="Linear" DropDownContainerHeight="50px" DropDownContainerMaxHeight="100px" DropDownContainerWidth="150px" EnableDropDownAsChild="True" Height="18px" MultipleSelectionType="Checkbox" PageSize="0" TextField="IndustryName" ValueField="IRecId" Width="150px" DropDownAnimationDuration="250"><DropDownItemBinding TextField="IndustryName" ValueField="IRecId" /><Button ImageUrl="~/Images/WDdl.gif" pressedimageurl="~/Images/WDdl_Up.gif" /></ig:WebDropDown>
Hi walles,
When you click "Previous", how do you update the CurrentValue? CurrentValue is just the Text shown in the input. When you change it, it won't affect the selection.
I suggest to either Bind the Value field to the same data (page number), and setting SelectedValue instead - it will automatically update both the selection and the Text (CurrentValue) - as it is in Microsoft's DropDownList.
Additionally, if you still want to use the CurrentValue, you can manually find the new selected item and set it to Selected. (again, using the SelectedValue should be the better approach).
The purpose of CurrentValue is when we have auto-suggest filtering functionality, and the user can freely type anything in the input box - then we don't have 1:1 correspondence between "current" input value, and Selected item's Text.
Please let me know if this helps and how i can help further.
Hi Angel,
Thanks for the reply.
I've tried updating the WebDropDown several ways;
However by WebDropDown is not bound to any data, I simply populate the WebDropDown at runtime using a loop that adds the numbers from 1 to the maximum page number. For example;
For iCount As Integer = 1 To totalPageNumbers WebDropDown.Items.Add(New Infragistics.Web.UI.ListControls.DropDownItem(iCount, iCount))Next
Should I be binding the WebDropDown to a datasource to allow setting SelectedValue to work? If so, I'll try binding to an array of page numbers.
Ian.
Hi Ian,
I have prepared a WebSite (attached) which has 2 dropdowns, in one items are added in markup, in the second items are added as you have shown above (using a for loop). I set SelectedValue after the items are added. I don't call DataBind() explicitly in that case. Not sure if this will work for you, please let me know if it doesn't.
You don't need to bind the control to a datasource to get SelectedValue to work.
P.S: When you bind to data source, and use SelectedValue, make sure to have ValueField in the items binding set to the correct field in the data source.
Thanks for the reply and the attached example.
Unfortunately the example provided isn't working as I'd expect it to. I've also recoded your example in VB.NET and it still isn't working.
I did notice that you have referenced "Infragistics35.Web.v9.2" whereas I am referencing "Infragistics35.Web.v9.1". I have downloaded the latest NetAdvantage for .NET (2009 vol 2) but the download contains "NetAdvantage_ASPNET_20091.exe" which seems to be the same package that was in 2009 vol 1.
To updated to "Infragistics35.Web.v9.2" is there something else I should be doing? Maybe this is will resolve my issue?
Any progess with this issue?
Thanks, i will investigate.
Thanks for the reply. Your 2nd paragraph gave me an idea, I have resolved the issue by manipulating the style set (in the CSS) for each of the ListItem states and that has allowed me to achieve the "look and feel" that I want. Essentially I just apply a style to the ListItemDisabled (current page) and the ListItemHover. Works nicely.
Before doing that I did attempt to set "Activated" when setting the selected value (activating the corresponding item in the list) and this raised an exception from the WebDropDown - "Object reference not set ....". You may want to pass this on.
Yep, it makes perfect sense to me:) There was an internal issue reported about a similar behavior, the number is 22103, one thing that is possible is that it didn't get into the latest service release.
By the way, the "gray" style for the Default StyleSet is for the Selected style , while the blue one is for Active item style, i.e. if an item is both selected and active, it will have blue style ,because it will be applied over the gray one.
I've updated to the latest service release and the issue I have is still persisting.
To expand on my last post, if you use the buttons without selecting an item in the dropdown (via the mouse) then the highlighting changes to match the number displayed in the collapsed dropdown - this is a grey highlighting. If you select an item using the mouse, this is highlighted in blue and it does not change when a button is pressed and you end up with 2 separate highlighted numbers, a grey and a blue - the grey matches the number in the collapsed dropdown and the blue stays on whatever was last selected by the mouse.
Hope that makes sense?
Thanks for the sample. First thing i notice is that you use the original initial release build 1015. Please upgrade to the latest service release where the issues you are facing should be fixed.