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

looping through combox items

2 Answers 620 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Binary
Top achievements
Rank 1
Binary asked on 25 Sep 2015, 03:09 PM

I have the telerik radcombox and I want to loop through all the items on that radcombox before adding any element to it. I want to achieve this at client side.I tried this code but it did not give result I was expecting for. I have application which will add items to the radcombox but before that I want to check element is already there or not. Not sure why my below code is not working.

 

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

var items = combo.get_items();

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

    var myradcomboValues= items.getItem(i);

  alert(myradcomboValues);

}

2 Answers, 1 is accepted

Sort by
0
Accepted
Eyup
Telerik team
answered on 30 Sep 2015, 09:22 AM
Hi Binary,

Please try the following snippet and let me know about the result:
function pageLoad(app, args) {
    var combo = $find('<%= RadComboBox1.ClientID %>');
    var items = combo.get_items();
    for (var i = 0; i < items.get_count() ; i++) {
        var item = items.getItem(i);
        var value = item.get_value();
        alert(value);
    }
}

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Johnny
Top achievements
Rank 3
Bronze
Iron
Iron
answered on 22 Aug 2022, 12:58 PM | edited on 29 Aug 2022, 10:01 AM

For future reference and to whoever might need it: if you wish to loop through the RadComboBox via codebehind (VB) instead of client-side, here's how:

Dim i As Integer = 0
For Each item In RadComboBox1.Items
    i = i + 1
    '[... Whatever you wish to do here ....]
Next

This way you can do whatever you wish to do within the for each loop, and count the number of items at the same time using the integer i.

Have a good day!

Rumen
Telerik team
commented on 23 Aug 2022, 12:37 PM

Thanks Johnny!

And here is the C# version too:

int i = 0;
foreach (var item in RadComboBox1.Items) {
        i = i + 1;
        // [... Whatever you wish to do here ....]
}

Tags
ComboBox
Asked by
Binary
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Johnny
Top achievements
Rank 3
Bronze
Iron
Iron
Share this question
or