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

Access checked items in C#

8 Answers 1337 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Dona
Top achievements
Rank 1
Dona asked on 17 Jul 2013, 06:46 PM
Hi

There is a radcombobox with checkboxes enabled and how can I access all the checked items in C# code?

Thanks all
Dona.

8 Answers, 1 is accepted

Sort by
0
A2H
Top achievements
Rank 1
answered on 18 Jul 2013, 03:22 AM
Hello,

You can use the RadCombobox's "CheckedItems" propertie to get all items which are checked.

Ex:
var collection = comboBox.CheckedItems;

Please refer the link which will give you complete details.

Thanks,
A2H

0
Dona
Top achievements
Rank 1
answered on 18 Jul 2013, 09:36 AM
Not working. I am getting Count=3 on debugging. I want to access all those values of items.
0
Princy
Top achievements
Rank 2
answered on 18 Jul 2013, 09:44 AM
Hi Dona,

Please try the following C# code.

C#:
foreach (RadComboBoxItem checkeditem in RadComboBox1.CheckedItems)
{
    string _value = checkeditem.Value; //looping through each checked item and accessing its value.
}

Thanks,
Princy.
0
Rajeeve
Top achievements
Rank 1
answered on 11 Aug 2016, 10:37 AM

to get the checked combobox values in telerik (using javascript)

var checkeditems;

var combo = $find("<%= telerikcomboboxname.ClientID%>")

 var items = combo.get_checkedItems();

  for (i = 0; i < items.length; i++) {

                        if (i == 0) {
                            radvalue = Number(parseInt(items[i]._properties._data.value));
                           checkeditems=checkeditems+radvalue ;
                        }
                        else {
                            radvalue = Number(parseInt(items[i]._properties._data.value));
                            checkeditems= checkeditems+ "," + radvalue;
                        }

               }
                    alert(Expenseitems);

 

this will work 

thanks all

0
Veselin Tsvetanov
Telerik team
answered on 16 Aug 2016, 07:06 AM
Hi Rajeeve,

Thank you for the suggested solution.

Note that this topic is on accessing checked items in the code-behind (C# / VB), while your suggestion is a client-side solution.

Note also that you won't need to use private properties (_properties and _data) of the RadComboBoxItem object to access the values of the item. You could freely use instead the get_value() method from the exposed client-side API of the object.

Moreover, if you do not initially set an empty string as a value of the checkeditems variable, it will produce the final result to have an "undefined" as prefix. In your suggestion, you also alert the wrong variable (Expenseitems), while the values are held in the checkeditems.

Modified working version of your sample code would be:
var checkeditems = '';
var radvalue;
var combo = $find("<%= RadComboBox1.ClientID%>")
var items = combo.get_checkedItems();
for (i = 0; i < items.length; i++) {
    radvalue = items[i].get_value();
    if (i == 0) {
        checkeditems = checkeditems + radvalue;
    }
    else {
        checkeditems = checkeditems + "," + radvalue;
    }
}
alert(checkeditems);

Regards,
Veselin Tsvetanov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Rajeeve
Top achievements
Rank 1
answered on 16 Aug 2016, 07:33 AM
yaaa you are right
0
jamsheer
Top achievements
Rank 1
Veteran
answered on 25 Apr 2017, 06:36 AM
Hi Veselin Tsvetanov,
      Here I am using a RadCheckedDropDownList for multi select value. Where I want all checked values of   RadCheckedDropDownList  to the datatable.
Please Refer how could I add to the datatable the checked values  from the checked list of RadCheckedDropDownList.
I need Like this : ' if(Checkeddrpdwnlist1.checked==true) ' then the value to datatable.
Thanks 
Jamsheer
0
jamsheer
Top achievements
Rank 1
Veteran
answered on 26 Apr 2017, 04:43 AM
Hi Veselin Tsvetanov,
      Looking for your answer ,Hope you got my question.
Thanks 
Jamsheer
Tags
ComboBox
Asked by
Dona
Top achievements
Rank 1
Answers by
A2H
Top achievements
Rank 1
Dona
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Rajeeve
Top achievements
Rank 1
Veselin Tsvetanov
Telerik team
jamsheer
Top achievements
Rank 1
Veteran
Share this question
or