RADComboBox not getting value on selectedIndexChanged.

1 Answer 12 Views
ComboBox
Manish
Top achievements
Rank 1
Manish asked on 15 Nov 2022, 09:26 AM

<telerik:RadComboBox ID="lblPayrollNumber" runat="server" AutoPostBack="true" Style="cursor: pointer;"
                                EnableVirtualScrolling="true" Skin="Outlook" OnSelectedIndexChanged="lblPayrollNumber_SelectedIndexChanged">
                                <Items>
                                    <telerik:RadComboBoxItem runat="server" Text="SAP Contract Number:" Value="1"></telerik:RadComboBoxItem>
                                    <telerik:RadComboBoxItem runat="server" Text="Existing WBS Number:" Value="2"></telerik:RadComboBoxItem>
                                    <telerik:RadComboBoxItem runat="server" Text="Request ID:" Value="3"></telerik:RadComboBoxItem>
                                </Items>
</telerik:RadComboBox>

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Code behind

 protected void lblPayrollNumber_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)

{

var val1 = e.Value;  Always getting value 1 doesn't matter which one you selected

var text1 = e.Value; getting right text

 

 if (lblPayrollNumber.SelectedValue == "1") Always getting value 1 doesn't matter which one you selected

 if (lblPayrollNumber.SelectedValue == "2") Always getting value 1 doesn't matter which one you selected

 if (lblPayrollNumber.SelectedValue == "3") Always getting value 1 doesn't matter which one you selected

}

1 Answer, 1 is accepted

Sort by
0
Valentin Dragnev
Telerik team
answered on 18 Nov 2022, 10:09 AM | edited on 18 Nov 2022, 10:11 AM

Hello Manish,

There is nothing wrong with the code you shared. I've tested it and it is working as expected.

You can also test it, but for that create a new WebForms (aspx) page to make sure there is nothing else that could conflict, and add the following code to it:

 

<telerik:RadComboBox ID="lblPayrollNumber" runat="server" AutoPostBack="true" Style="cursor: pointer;"
    EnableVirtualScrolling="true" Skin="Outlook" OnSelectedIndexChanged="lblPayrollNumber_SelectedIndexChanged">
    <Items>
        <telerik:RadComboBoxItem runat="server" Text="SAP Contract Number:" Value="1"></telerik:RadComboBoxItem>
        <telerik:RadComboBoxItem runat="server" Text="Existing WBS Number:" Value="2"></telerik:RadComboBoxItem>
        <telerik:RadComboBoxItem runat="server" Text="Request ID:" Value="3"></telerik:RadComboBoxItem>
    </Items>
</telerik:RadComboBox>

<telerik:RadTextBox runat="server" ID="RadTextBox1" Label=""></telerik:RadTextBox>
<telerik:RadTextBox runat="server" ID="RadTextBox2" Label=""></telerik:RadTextBox>

<script runat="server">
    protected void lblPayrollNumber_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadTextBox1.Text = e.Value;
        RadTextBox2.Text = e.Text;
    }
</script>

 

 

On the page where this is not working, there might be a line of code that changes/resets the Combo's selected value.

Please review the rest of the code on the page, more specifically the lines that are making changes to the combo. You can try and search by the keyword "lblPayrollNumber" to find all lines where the combo is involved and inspect the results. Be sure, that no other line of code on the page is changing/resetting the Combo's selected value or text.

 

Furthermore, the event arguments of the ComboBox contain event-related information, such as the selected text/value. You can access them directly from the argument (e.Text, e.Value).

 

protected void lblPayrollNumber_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    // Instead of referencing the combo by its ID and getting the selected value like in this line: 
    //  if (lblPayrollNumber.SelectedValue == "1")

    // use the information provided in the Event arguments (e.Text, e.Value)
    if (e.Value == "1")
    {

    }

    // OR 
    if (e.Text == "1")
    {

    }
}

 

 

Regards,
Valentin Dragnev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ComboBox
Asked by
Manish
Top achievements
Rank 1
Answers by
Valentin Dragnev
Telerik team
Share this question
or