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

ComboBox using AjaxBind doesn't select the item on when the page is loaded

2 Answers 90 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.
Nathan
Top achievements
Rank 1
Nathan asked on 01 Jul 2011, 06:00 PM
Hi,

I am using a ComboBox with ajax bindings. When I initially select the item & post to the server and back the selected value is maintained correctly (think create page). However if I then load a page and set the value the item is not selected in the combo box (think edit page).

e.g.

@(Html.Telerik().ComboBoxFor(m => m.ModelId)
                .DataBinding(binding => binding.Ajax().Select("Method", "Controller"))
                .Filterable(filtering =>{filtering.FilterMode(AutoCompleteFilterMode.Contains);})
                .HighlightFirstMatch(true).HtmlAttributes(new { style = "width:260px" })
        )

m.ModelId is correctly set with the value and the javascript initalizer is created as 
jQuery('#OrderItems\\[2\\]_ModelId').tComboBox({autoFill:false, ajax:{"selectUrl":"/Controller/Method"}, filter:2, selectedValue:'3473'});

However the page loads up and the combobox remains empty. If I then open the combobox it loads the items from the server and selects the correct one automatically.

Is there a way to make it load the item from the server and select it automatically on page load.

Thanks

Nathan

2 Answers, 1 is accepted

Sort by
0
Wahid
Top achievements
Rank 2
answered on 27 Aug 2011, 01:32 PM
Like this post

Just reload it:
e.g.
<%: Html.Telerik()
.ComboBoxFor(m => m)
.AutoFill(true)
.DataBinding(binding => binding.Ajax().Select("ForCombobox", "Categories"))
.ClientEvents(e=>e.OnLoad("onAjaxComboLoad")) %>

Then JavaScript :
function onAjaxComboLoad(e) {
    $(e.target).data("tComboBox").reload();
}
0
bbeatty
Top achievements
Rank 1
answered on 09 Feb 2012, 12:38 AM
How would you do this for a DropDownList?

Tags
ComboBox
Asked by
Nathan
Top achievements
Rank 1
Answers by
Wahid
Top achievements
Rank 2
bbeatty
Top achievements
Rank 1
Share this question
or