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>
As you can see in the Image, The CurrentValue or what is displayed is not Biotechnololgy. The SelectedValue was set to 5 (Biotechnololgy) and the control is 1 (Agriculture).
It has been my experance that submitting a bug to developer support is that you have to prove the problem before they will even look at it. I have been working on this problem for 4 days now and if I cant get it fixed by today, I will have to look for another control or toolset.
Hi dmhsas,
I have created a project (attached), and you are right that there is a bug. In the meantime i have provided a workaround (to set the CurrentValue to "") before setting SelectedValue - in Default.aspx, which works fine.
This is done in Page_Load in the code behind. You can also additionally check whether FindByValue returns an item or not (and if it returns not, you may not reset CurrentValue).
You can expect the fix to this in the first hotfix for 2009.1.
Thanks very much for your input ,
Hi Angel,
I'm also having difficulty setting the selected item of the WebDropDown. The display mode for my list is DropDownList. The WebDropDown is part of a User Control that is used as a pagination control, therefore the list simply contains a list of numbers from 1 to the total number of pages available. The User Control also contains Buttons to move forwards or backwards through the pages. I'm trying to update the WebDropDown when one of these pages is clicked so that the list in the WebDropDown corresponds to that page being viewed.
Using the above code that sets the CurrentValue works partially - when the buttons are clicked the value displayed in the WebDropDown changes accordingly, however when the WebDropDown is selected and the entire list shown, the highlighted ListItem does not match the CurrentValue.
For example, if I select the WebDropDown and then select page 4, the fourth page is displayed and the number 4 becomes highlighted. If I then select the "Previous" Button, the page changes and the value displayed in the collapsed WebDropDown changes to 3. If I then select the WebDropDown and the full list is displyed, the ListIem 4 remains highlighted in the list, when ideally it should be the ListItem 3 that is highlighted.
Any help would be greatly appreciated.
Thanks.
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.
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,
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.