Problem with SelectedValue

6 posts, 0 answers
  1. John Schroeder
    John Schroeder avatar
    11 posts
    Member since:
    Nov 2009

    Posted 27 Sep 2011 Link to this post

    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.
  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 28 Sep 2011 Link to this post

    Hello John,

    Are the values in your RadComboBox coming from a DataSource control? If so, you should databind the control before setting the SelectedValue.
  3. John Schroeder
    John Schroeder avatar
    11 posts
    Member since:
    Nov 2009

    Posted 28 Sep 2011 Link to this post

    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.
  4. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 30 Sep 2011 Link to this post

    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
  5. John Schroeder
    John Schroeder avatar
    11 posts
    Member since:
    Nov 2009

    Posted 30 Sep 2011 Link to this post

    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.
  6. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 05 Oct 2011 Link to this post

    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
Back to Top