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>
With some trial an error, I came up with what I think is a bug in the control.
1. The control dosent seem to be loading the data from the SqlDataControl on the postback. Before I can do a FindByValue I have to reset the data items.
WebDropDown.DataKeyFields = "IRecId"WebDropDown.TextField = "IndustryName"WebDropDown.ValueField = "IRecId"WebDropDown.DataBind()
2. Once I do the above reset of the data items. I then do the FindByValue on the control finds the data, But if you look at the Image, you can see the it is selected but it is not shown in the top display field. I can tell its selected, because of the gray box around it. The red arrow is what is displayed on page display and the blue arrow shows that the correct item is selected in the dropdown.
Thanks very much for your feedback.
If you feel this is a bug in the control, please submit an incident to the Development Support using this link:
Submit an incident to Infragistics Developer Support
In general, what is shown in the input box is related to the CurrentValue property. It doesn't have to be associated with any item's Text or Value fields, because a user can type anything in the input (depending on the mode of the control), which doesn't match a specific item. When you explicitly set SelectedValue, the CurrentValue (hence, the input value as well) will be automatically updated to the item's Text value.
Assuming that the Biotechnology item's Value is 123, and its text == "Biotechnology" , if we do:
WebDropDown1.SelectedValue = "123"; // if there is a match, the Biotechnology item will be selected, and the CurrentValue / input value will be updated to the text "Biotechnology"
Hope this helps,
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 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.
Ian.
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.