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

radiobutton in itemtemplate

6 Answers 297 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
newbie
Top achievements
Rank 1
newbie asked on 07 Apr 2009, 06:35 PM
I have implemented a combobox with multiselect using checkboxes.
Along with this functionality I also want to provide radio buttons next to the checkboxes.

The requirement is that the user should be able to select multi items in the combo and mark one of them as the default value.

The multi-select is working perfectly for me, I am unable to figure out how to get the radio buttons.

Can you help me with this requirement?

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Apr 2009, 08:02 AM
Hello,

You can try out the following code to achieve the required scenario:
aspx:
<telerik:RadComboBox runat="server" ID="RadComboBox1" HighlightTemplatedItems="true"
                <Items> 
                   ..... 
                </Items> 
                <ItemTemplate>     
                    <asp:RadioButton ID="RadioButton1" runat="server" />   
     
                    <asp:CheckBox runat="server" ID="CheckBox"/>                  
                </ItemTemplate>                
</telerik:RadComboBox> 

C#:
 
   protected void Page_Load(object sender, EventArgs e)  
    {  
       setGrdRadioButtonOnClick();   
    }   
   
  
    public void setGrdRadioButtonOnClick()  
    {  
        foreach (RadComboBoxItem item in RadComboBox1.Items)  
        {  
            RadioButton radioButton = (RadioButton)item.FindControl("RadioButton1"); // access the RadioButton 
            radioButton.Attributes.Add("OnClick""SelectOneOnly(" + radioButton.ClientID + ", " + "'RadComboBox1'" + ")");  
        }  
    }  

js:
<script type="text/javascript"
       function SelectOneOnly(radioButton, combo)  
       {   
           for (var i=0; i<document.all.length; i++)  
             {  
              var obj = document.all(i);               
              if (obj.type == "radio")  
               {                  
                 if (radioButton.id.substr(0, combo.length) == combo)  
                 if (radioButton.id == obj.id)  
                     obj.checked = true;  
                 else  
                     obj.checked = false;  
               }  
             }      
       }       
</script> 

Thanks
Princy.
0
newbie
Top achievements
Rank 1
answered on 09 Apr 2009, 05:37 PM
Thanks.

I also want to have a default selection in my combo box. I am able to select the radiobutton for the default selection.
I want to display the selected text in the Combo TextBox.

This is the code that I am using:

foreach

(RadComboBoxItem item in combo.Items)

 

{

 

if (item.Text == "default") // get the default value

 

{

RadioButton rb = (RadioButton)item.FindControl("RadioButton1");

 

rb.Checked =

true;
combo.Text = item.Text;
}

 

}

But combo.Text does not display the text value.

0
Veselin Vasilev
Telerik team
answered on 10 Apr 2009, 08:11 AM
Hello,

You need to set the AllowCustomText property of the combobox to True.

Sincerely yours,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
newbie
Top achievements
Rank 1
answered on 10 Apr 2009, 07:45 PM
setting allowcustomtext property to true does not show the text in the combo input.

I just wanted to add that I am using LoadOnDemand.

So, I am setting the text value in the ItemsRequested event handler.
0
Veselin Vasilev
Telerik team
answered on 13 Apr 2009, 03:31 PM
Hello,

In ItemsRequested server event you can only add items to the combobox. You cannot set any of its properties (including the Text property).
What you can do is to subscribe to the OnClientItemsRequested event and use the javascript method set_text() to set the text of the combobox or just select one of the loaded items.
Here are both approaches:

function onClientRequested(sender, e) 
   // set a custom text 
   sender.set_text("Please select an item"); 
</sc 

and

function onClientRequested(sender, e) 
    //select the first item 
    sender.get_items().getItem(0).select();   

I hope this helps.

Best wishes,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Mark
Top achievements
Rank 2
answered on 11 Dec 2018, 09:50 PM

This is a great work around that still appears relevant in 2018!

Thanks!

-Mark

Tags
ComboBox
Asked by
newbie
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
newbie
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Mark
Top achievements
Rank 2
Share this question
or