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

how to select an item after binding it on client side

2 Answers 90 Views
UI for ASP.NET AJAX in ASP.NET MVC
This is a migrated thread and some comments may be shown as answers.
Sub
Top achievements
Rank 1
Sub asked on 27 Apr 2009, 09:05 PM
Hi,

I am loading the dropdown on client side page load by calling the Controller action that returs JSON object. The callback function looks as below:

function

 

(result) {

 

 

debugger;

 

comboBox = $find(

"<%= comboBox.ClientID%>");

 

 

for (var i = 0; i < $(result).length; i++) {

 

 

var item = result[i];

 

 

var comboItem = new Telerik.Web.UI.RadComboBoxItem();

 

comboItem.set_text(item.FullDescription);

comboItem.set_value(item.PatientIdentifier);

comboBox .get_items().add(comboItem);

 

if (item.PatientIdentifier == patId) {

 

comboItem.select();

}

}

});


It populates the combobox except the selection. When calling select() it throws an exception in the following line:

__doPostBack(

'ctl00$PageHeadTitle$comboBox','{"Command":"Select","Index":0}')

I tried to cancel the default behavior as below:

 

// This cancels the default RadComboBox behavior

 

 

 

 

function itemsRequesting(sender, args) {

 

args.set_cancel(

true);

 

}

It does not select the given item. Please guide me about how to select an item after binding it on client side.

Thanks

2 Answers, 1 is accepted

Sort by
0
Dallas Sehlhorst
Top achievements
Rank 1
answered on 28 Apr 2009, 02:26 AM
Sub-

I ran into the exact same problem- I ended up solving it by hooking the RadComboBox's OnClientItemDataBound event and then calling sender.set_value(valueId).  It works when you define the selected item on the RadComboBox, not the individual RadComboBoxItem.

Define ComboBox:

<telerik:RadComboBox runat="server" ID="radFacility" OnClientItemDataBound="highlightProject"

And this JS:

function highlightProject(sender, args) { 
   sender.set_value(projectId); 

Hopefully this will work for you.

-Dallas

0
Sub
Top achievements
Rank 1
answered on 28 Apr 2009, 02:27 PM
Dallas,

My original code works after removing the AutoPostBack= true which was causing the error. I did not have to use OnClientItemDataBound event. It works with out it.

Thanks
Tags
UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Sub
Top achievements
Rank 1
Answers by
Dallas Sehlhorst
Top achievements
Rank 1
Sub
Top achievements
Rank 1
Share this question
or