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

Different selecttext on closed combo

3 Answers 30 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 09 Apr 2015, 12:32 PM

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

 

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Plamen
Telerik team
answered on 10 Apr 2015, 07:17 AM
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.

 
0
Mark
Top achievements
Rank 1
answered on 10 Apr 2015, 11:09 AM

 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 ?

 

 

 

 

 

0
Accepted
Plamen
Telerik team
answered on 10 Apr 2015, 12:30 PM
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.

 
Tags
ComboBox
Asked by
Mark
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Mark
Top achievements
Rank 1
Share this question
or