Different selecttext on closed combo

4 posts, 2 answers
  1. Mark
    Mark avatar
    36 posts
    Member since:
    Mar 2014

    Posted 09 Apr 2015 Link to this post

    Hello

    Any hints on how to solve this in javascript ?

     I need radcombo to show normal selecttext list when open, but a different selecttext when closed.

     ex. Items a,b,c    

      when "b" selected and radcombo closes i should show "mytext"

     

    any clues would be appreciated.

     

    regards

    Mark

     

     

  2. Answer
    Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 10 Apr 2015 Link to this post

    Hello Mark,

    Here is the code that worked at my side:
    <script type="text/javascript">
     
           function OnClientDropDownClosed(sender, args) {
               if (sender.get_selectedItem().get_text() === "b") {
                   sender.set_text("some other text");
               }
           }
       </script>
     
           <telerik:RadComboBox runat="server" OnClientDropDownClosed="OnClientDropDownClosed" >
               <Items>
                   <telerik:RadComboBoxItem Text="a" />
                   <telerik:RadComboBoxItem Text="b" />
                   <telerik:RadComboBoxItem Text="c" />
               </Items>
     
           </telerik:RadComboBox>

    Hope this will be helpful.


    Regards,
    Plamen
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mark
    Mark avatar
    36 posts
    Member since:
    Mar 2014

    Posted 10 Apr 2015 in reply to Plamen Link to this post

     Thanks  Plamen , it works like a charm.

    now if I may go a bit further , I need to set the  custom text from serverside too?

    I tried this without luck:

             for (int i = 0; i <= 3; i++)

            {
                RadComboBoxItem ci = new RadComboBoxItem(i.ToString());

                if (i == 2)
                    ci.Selected=true;

                RadComboBox1.Items.Add(ci);
            }

         // RadComboBox1.SelectedItem.Text = "mytext";
         // RadComboBox1.Text = "mytext";

      I suspect i need to use an event ?

     

     

     

     

     

  5. Answer
    Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 10 Apr 2015 Link to this post

    Hello,

    By Default setting a selected item is defining the text in RadComboBox. that is why having both a selected item and a different text from the serve is not supported unless you change the text of the selected item as you can see if you uncomment the following line:
    RadComboBox1.SelectedItem.Text = "mytext";

    If you need such functionality you will have to do it from the client side.

    Regards,
    Plamen
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top