How do I prevent this?
<telerik:RadDropDownList ID="ddlShippingMethod" runat="server" Width="300" DropDownHeight="200" />
VB code behind...
ddlShippingMethod.DataSource = ShippingMethodMaster.GetShippingMethodMasters(_ServerName, _DatabaseName)
ddlShippingMethod.DataTextField = "ServiceDescription"
ddlShippingMethod.DataValueField = "ShippingMethod"
ddlShippingMethod.SelectedValue = _brlCustomer.ShippingMethod
7 Answers, 1 is accepted
The experienced behavior is expected and it is by design, since the RadDropDownListItems are initiated with an empty value, if there is not explicitly set any. Setting ddlShippingMethod.SelectedValue = ""; should not change the current selection of the RadDropDownList.
The asp DropDownList control will correctly set the SelectedValue to the element with the blank value.
I need to know how to use the RadDropDownList to accomplish this.
I would suggest you to use the FindItemByText() method of the RadDropDownList and find the item by its text value instead of its value. In addition to the above, you could use the Selected() property of the DropDownListItem, in order to set it as selected. Please consider the following approach:
Using the FindItemByText would not seem to make any sense since the the DataValueField is what is stored in the customer database record and not the DataTextField! Using FindItemByText would require a separate lookup of the ShippingMethods table to find the empty value "ShippingMethod" just to locate the "ServiceDecsription" to use in the FindItemByText.
I was able to find two workarounds but I don't consider either of them to be viable.
First, I found that I could set the _brlCustomer.ShippingMethod = " " (i.e. a space) instead of ="" (i.e. an empty string).
This is not viable because a space character should not evaluate as "equal to" an empty string in most environments.
The second workaround was to use the FindItemByValue as follows:
However, this seems kludgy because the "FindItemByValue" line is NOT required when using an asp:DropDownList control and I don't want to have to change all of our code depending on whether we choose to use the telerik:RadDropDownList or the asp:DropDownList.
I must reiterate that the standard Microsoft asp:DropDownList control correctly binds an empty string data value.
It seems like the RadDropDownList should behave in an identical manner.
The fact that it does not seems like a bug in your control.
I have logged your request in our Ideas & Feedback Portal. You could vote for the implementation of the desired functionality here.
var itemShippingMethod = ddlShippingMethod.findItemByValue(SoldToInfo.ShippingMethod);
Could you please fix this problem on your client-side script the same way you fixed in on the code-behind?
Indeed you have a point and I have forwarded this case to our developer team. However, currently you can implement a workaround, by creating a helper function, where you can pass the DropDownList and the value, upon which you need to find certain item. In the function you can loop trough the items collection and get each item's value and compare it with the passed one. Thus, if an empty string is passed to the function, in the loop you will be able to acquire the item with value "".