RadDropDownList not databinding to blank field

8 posts, 0 answers
  1. Dennis
    Dennis avatar
    9 posts
    Member since:
    Jan 2013

    Posted 02 Jul 2013 Link to this post

    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()
  2. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 05 Jul 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dennis
    Dennis avatar
    9 posts
    Member since:
    Jan 2013

    Posted 05 Jul 2013 Link to this post

    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.
  5. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 10 Jul 2013 Link to this post

    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.
  6. Dennis
    Dennis avatar
    9 posts
    Member since:
    Jan 2013

    Posted 10 Jul 2013 Link to this post

    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.
  7. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 15 Jul 2013 Link to this post

    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.
  8. Dennis
    Dennis avatar
    9 posts
    Member since:
    Jan 2013

    Posted 29 Oct 2015 Link to this post

    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?

     

  9. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 03 Nov 2015 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017