This is a migrated thread and some comments may be shown as answers.

RadDropDownList not databinding to blank field

7 Answers 219 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 2
Dennis asked on 02 Jul 2013, 11:51 PM
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()

7 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 05 Jul 2013, 10:46 AM
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
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.
0
Nencho
Telerik team
answered on 10 Jul 2013, 10:55 AM
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:

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:

        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
Nencho
Telerik team
answered on 15 Jul 2013, 12:19 PM
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
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
Nencho
Telerik team
answered on 03 Nov 2015, 01:50 PM
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
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
Tags
DropDownList
Asked by
Dennis
Top achievements
Rank 2
Answers by
Nencho
Telerik team
Dennis
Top achievements
Rank 2
Share this question
or