how to select an item after binding it on client side

Thread is closed for posting
3 posts, 0 answers
  1. Sub
    Sub avatar
    91 posts
    Member since:
    Nov 2007

    Posted 27 Apr 2009 Link to this post

    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. Dallas Sehlhorst
    Dallas Sehlhorst avatar
    19 posts
    Member since:
    Feb 2006

    Posted 27 Apr 2009 Link to this post

    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

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sub
    Sub avatar
    91 posts
    Member since:
    Nov 2007

    Posted 28 Apr 2009 Link to this post

    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
Back to Top