Setting ComboBox Selected value

5 posts, 0 answers
  1. slken
    slken avatar
    32 posts
    Member since:
    Jul 2006

    Posted 31 Mar 2014 Link to this post

    I have a RadComboBox which is setup to populate the RadComboBoxItems as the user types in characters using a webservice.

    Let's say the page was just loaded and the user hasn't clicked on the combobox yet. Meaning there are no values in the list yet.

    How could I set the selected value of the combobox from a button click event?

    I've seen code for the client side:

    <telerik:RadScriptBlock runat=

     

    "server"

    >​​​

     

     

     

     

    var

    secCombo = $find(

    "<%= rcbCombo.ClientID %>"

    );

     

    </telerik:RadScriptBlock>

    secCombo.set_text(selectedName

     

     

    );​​​​​​​​

     

    secCombo.set_value(selectedValue);

    I've also seen server side code like:

    ​​​​​​​​​​

     

     

     

     

    RadComboBoxItem

    item = rcb_securities_list.FindItemByText(selectedName);

     

    item.Selected =

     

     

    true

    ;

     

    But I think neither is working because either EnableAutomaticLoadOnDemand is enabled or due to the control has no values loaded yet.

    How can I set the value?

     

     

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Apr 2014 in reply to slken Link to this post

    Hi slken,

    RadComboBox items loaded on demand using the ItemsRequested event handler or WebService do not exist on the server and cannot be accessed using the server-side FindItemByText / Value methodsSelectedItem and SelectedIndex properties are always Null / Nothing.This is needed for speed (otherwise the combobox will not be that responsive upon each keypress if state information and ViewState were persisted). The properties that are accessible on the server are: Text and SelectedValue.

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. slken
    slken avatar
    32 posts
    Member since:
    Jul 2006

    Posted 01 Apr 2014 in reply to Shinu Link to this post

    Thanks for the insightful information.

    I'm still unsure how I can approach attaining what I need to do.

    Along with the RadComboBox, I have a jQuery modal form which allows users to search for values. Upon selection on the modal form, I would like to set the value of the RadComboBox using the selected value.

    How can I do that?
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 Apr 2014 in reply to slken Link to this post

    Hi slken,

    Please have a look into the following sample code snippet to achieve your scenario.

    ASPX:
    <telerik:RadTextBox ID="RadTextBox1" runat="server">
    </telerik:RadTextBox>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Click" AutoPostBack="false"
        OnClientClicked="OnClientClicked">
    </telerik:RadButton>
    <telerik:RadComboBox ID="RadComboBox1" runat="server" Width="250" Height="150"  EnableLoadOnDemand="true" ShowMoreResultsBox="true" EnableVirtualScrolling="true" OnClientItemsRequested="OnClientItemsRequested">
        <WebServiceSettings Method="GetCompanyNames" Path="Products.asmx" />
    </telerik:RadComboBox>

    JavaScript:
    <script type="text/javascript">
        var comboItem;
        function OnClientClicked(sender, args) {
            var textbox = $find("<%=RadTextBox1.ClientID %>");
            comboItem = textbox.get_value();
            var combo = $find("<%=RadComboBox1.ClientID %>");
            combo.requestItems(comboItem);
        }
        function OnClientItemsRequested(sender, eventArgs) {
            sender.findItemByText(comboItem).select();
        }
    </script>

    Thanks,
    Shinu.
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 Apr 2014 in reply to Shinu Link to this post

    Hi slken,

    In my previous post the function "OnClientItemsRequested" have some issues. So please try the following JavaScript to achieve your scenario.

    JavaScript:
    function OnClientItemsRequested(sender, args) {
        var item = sender.findItemByText(comboItem);
        if (item != null) {
            item.select();
        }
     
    }

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017