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

Problem with SelectedValue

5 Answers 38 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
John Schroeder
Top achievements
Rank 1
John Schroeder asked on 27 Sep 2011, 03:00 PM
Hello,

I have a problem with RadComboBox control. In my project I have several of them with static Items list specified in aspx for each one. During the page load I'm supposed to set the selected item of those combo boxes according to data stored in a database (values of those radcomboboxes). This is where the problem begins. When I use RadComboBox.SelectedValue = somevalue; the radcombobox shows the Text of the 1st item in its list instead of the selected item's Text. If I click on the dropdown I can clearly see that for example a 3rd item in the list is selected but the actual Text value is coming from the 1st item in the list. Looking here: http://www.telerik.com/help/aspnet-ajax/combobox-items-server-side-code.html under SELECTING ITEMS it clearly says that I can select items using SelectedValue (which is the same behavior in standard ASP.NET controls) however RadComboBox gives me this issue which I'm not sure how to resolve.

Best regards.

5 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 28 Sep 2011, 01:45 PM
Hello John,

Are the values in your RadComboBox coming from a DataSource control? If so, you should databind the control before setting the SelectedValue.
0
John Schroeder
Top achievements
Rank 1
answered on 29 Sep 2011, 03:28 AM
Hi Kevin,

My RadComboBox isn't bound to a datasource. It has a static set of items declared in aspx file itself. Like below:

<telerik:RadComboBox ID="RadComboBox1" runat="server">
                                            <Items>
                                                <telerik:RadComboBoxItem Text="Solid" Value="Solid" />
                                                <telerik:RadComboBoxItem Text="Double" Value="Double" />
                                                <telerik:RadComboBoxItem Text="Dotted" Value="Dotted" />
                                                <telerik:RadComboBoxItem Text="Dashed" Value="Dashed" />
                                                <telerik:RadComboBoxItem Text="Groove" Value="Groove" />
                                                <telerik:RadComboBoxItem Text="Ridge" Value="Ridge" />
                                                <telerik:RadComboBoxItem Text="Inset" Value="Inset" />
                                                <telerik:RadComboBoxItem Text="Outset" Value="Outset" />
                                                <telerik:RadComboBoxItem Text="None" Value="None" />
                                            </Items>
                                        </telerik:RadComboBox>

So here I obviously have no reason to use Databind() on the control itself. Any other ideas?

Regards.
0
Ivana
Telerik team
answered on 30 Sep 2011, 02:17 PM
Hi John,

I have tested the code you have provided, and when I set a selected value server-side everything work as it should. The RadComboBox's input field shows the text of the selected item.

Take a look at the following link to see how your code behaves at our end.

If you are still having troubles, please send us a support ticket with a runnable sample page demonstrating the issue.

Kind regards,
Ivana
the Telerik team
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 their blog feed now
0
John Schroeder
Top achievements
Rank 1
answered on 30 Sep 2011, 04:59 PM
Hi Ivana,

That's exactly what I'm doing in my code so I really don't understand what could be the issue here. Could it be the problem with the event I'm using to set these values? I'm using OnPreRenderComplete event of the page cycle to set these values. So to clarify again, the value IS SELECTED but the text isn't. It shows the text of the 1st item in the list while the value is selected and fine.

Regards.
0
Ivana
Telerik team
answered on 05 Oct 2011, 02:35 PM
Hello John,

Yes, the problem you are experiencing is because you are setting the selected item too late according to the asp.net page life cycle, when the text in the input field is already set.

One possible solution of this scenario could be to set the the selected item's text in the input field in the pageLoad() client-side method, as in the example bellow:

JavaScript:
function pageLoad() {
            var combo = $find("RadComboBox1");
            var inputArea = combo.get_inputDomElement();
            inputArea.value = combo.get_selectedItem().get_text();
        }
 

Or, you could set selected item for the RadComboBox, in the Page_Load method server-side.

Hope this helps.

Greetings,
Ivana
the Telerik team
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 their blog feed now
Tags
ComboBox
Asked by
John Schroeder
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
John Schroeder
Top achievements
Rank 1
Ivana
Telerik team
Share this question
or