Unplanned
Last Updated: 03 Feb 2023 08:37 by Tim
Tim
Created on: 03 Feb 2023 08:37
Category: ComboBox
Type: Bug Report
1
RadComboBox Selection issue when Item has no value and text has trailing space

I recently upgraded from ASP.NET AJAX 2014 to 2022 and ran into an issue with a RadComboBox. It can be reproduced with this code:

Test.aspx

     <telerik:RadScriptManager ID="scriptManager" runat="server" />
            <telerik:RadComboBox ID="rcb" runat="server" Label="Medication:" AutoPostBack="true"
                Width="250" OnSelectedIndexChanged="rcb_SelectedIndexChanged">
                <Items>
                    <telerik:RadComboBoxItem Text="-- select --" Value="" />
                    <telerik:RadComboBoxItem Text="Benztropine 0.5 mg " />
                    <telerik:RadComboBoxItem Text="Buspirone 10 MG" />
                    <telerik:RadComboBoxItem Text="Haloperidol 100mg/ml" />
                    <telerik:RadComboBoxItem Text="Metaprolol 25 mg" />
                    <telerik:RadComboBoxItem Text="Quetiapin/Seroquel 400 mg" />
                    <telerik:RadComboBoxItem Text="Trazadone 150 mg" />
                    <telerik:RadComboBoxItem Text="Vitamin D2 50,000 units" />
                </Items>
            </telerik:RadComboBox>
            <label>SelectedIndex</label> <asp:Label ID="Label1" runat="server" Text=""></asp:Label>

Test.aspx.cs

protected void rcb_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    Label1.Text = rcb.SelectedIndex.ToString();
    rcb.SelectedIndex = 0;
}

When "Benztropine 0.5 mg " is selected, the SelectedIndex in the selected index changed method is incorrectly set to 0, instead of 1. Selecting any other item in the list results in the correct SelectedIndex. I spent a lot of time debugging the code until I noticed that "Benztropine 0.5 mg " has a space at the end.

I found two workarounds:

1. Trim the trailing space from text.

2. Add values for each item.

This was not an issue with the old 2014 version. Is this a bug or am I missing something?

0 comments