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 ,
Hello Angle,
Do you also add to the bug report that I have to re-bind the control before I do a FindItem eventho its bound to a SqlDataSource that is on the form ? Here is the final codebehind I have to use to restore the database item. dr is a datarow.
Thanks for all the help on this.
IndustryDdl2.DataKeyFields = "IRecId"IndustryDdl2.TextField = "IndustryName"IndustryDdl2.ValueField = "IRecId"IndustryDdl2.DataBind()
If IndustryDdl2.Items.FindItemByValue(dr("IndustryId")) IsNot Nothing Then IndustryDdl2.CurrentValue = "" IndustryDdl2.SelectedValue = dr("IndustryId")End If
Hello,
Thanks again, i am very happy the scenario works fine now. All your feedback is greatly appreciated. About the DataBind() call - i will investigate further why this needs to be called and if it apperas to be a bug - we will file an issue.