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

[Solved] Set combobox value by Text

2 Answers 201 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael Pullella
Top achievements
Rank 1
Michael Pullella asked on 07 Feb 2011, 06:50 PM
Hi

I have a grid and a combobox on a form
When the user selects an item from the grid, I am setting the value of textboxes and an MVC Combobox based on the values that were in the grid row.

How can you set the value of a combobox based on text (sort of like FindItemByText in the RadCombobox)?


I can set the value by index like this:
$('#CategoryID').data('tComboBox').select(3);

I would like to set the value by text like this:
$('#CategoryID').data('tComboBox').select('ComboBoxItem3');

I suppose I could loop through all the items in the combobox until I find the one that matches the text, then select that.  Is there a better way?
Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Michael Pullella
Top achievements
Rank 1
answered on 07 Feb 2011, 07:32 PM
Here is what I ended up doing.  Is there a better way?

// e.row.cells[1].innerHTML is the value that I am matching (from the grid)
  
var combo = $('#CategoryID').data('tComboBox');
  
//fill in the combo
$.each(combo.data, function (key, value) {
    if (value.Text == e.row.cells[1].innerHTML) {
        combo.select(key);
        return;
    }
});
0
Accepted
Georgi Krustev
Telerik team
answered on 08 Feb 2011, 03:01 PM
Hello Michael,

 
You can pass predicate to the .select() method in order to select item with desired Item.Text:

$('#CategoryID').data('tComboBox').select('ComboBoxItem3');
 
var combobox = $('#CategoryID').data('tComboBox');
 
var selectItem = function(dataItem){
    //dataItem argument is a ComboBox data item.
    return dataItem.Text== "ComboBoxItem3";
}
 
combobox.select(selectItem);

For more information check this help topic.

Best wishes,
Georgi Krustev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
Michael Pullella
Top achievements
Rank 1
Answers by
Michael Pullella
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or