In the example below, when _brlCustomer.ShippingMethod = "", the ddlShippingMethod.SelectedValue appears to be getting set to the cached value from the previously viewed customer record. So if the previous customer had ShippingMethod = "GROUND" then adding a new customer subsequently is setting the SelectedValue = "GROUND" instead of SelectedValue = "".
How do I prevent this?
ASPX markup...
<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
ddlShippingMethod.DataBind()
How do I prevent this?
ASPX markup...
<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
ddlShippingMethod.DataBind()
7 Answers, 1 is accepted
0
Hello Dennis,
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.
Regards,
Nencho
Telerik
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.
Regards,
Nencho
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Dennis
Top achievements
Rank 2
answered on 05 Jul 2013, 06:24 PM
So how would I reset the RadDropDownList so that a new record will default to the empty string value rather than default to the value that was cached from the last customer record viewed?
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.
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.
0
Hello Dennis,
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:
Regards,
Nencho
Telerik
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:
ddlShippingMethod.FindItemByText(
"ItemText"
).Selected =
true
;
Regards,
Nencho
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Dennis
Top achievements
Rank 2
answered on 10 Jul 2013, 05:00 PM
Nencho,
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.
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:
ddlShippingMethod.DataSource = ShippingMethodMaster.GetShippingMethodMasters(_ServerName, _DatabaseName)
ddlShippingMethod.DataTextField =
"ServiceDescription"
ddlShippingMethod.DataValueField =
"ShippingMethod"
ddlShippingMethod.DataBind()
ddlShippingMethod.FindItemByValue(_brlCustomer.ShippingMethod).Selected =
True
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.
0
Hello Dennis,
I have logged your request in our Ideas & Feedback Portal. You could vote for the implementation of the desired functionality here.
Regards,
Nencho
Telerik
I have logged your request in our Ideas & Feedback Portal. You could vote for the implementation of the desired functionality here.
Regards,
Nencho
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Dennis
Top achievements
Rank 2
answered on 29 Oct 2015, 09:58 PM
Although you have since appeared to fix this problem in code-behind, this still appears to be a problem in Javascript.
If I use the Javascript method .findItemByValue and the SoldToInfo.ShippingMethod = "" (i.e. empty string) then the itemShippingMethod variable is incorrectly showing as "null".
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?
0
Hello Dennis,
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 "".
Regards,
Nencho
Telerik
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 "".
Regards,
Nencho
Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items