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

[Solved] Dropdownlist OnChange not firing after doing Select() method

0 Answers 157 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.
Richard
Top achievements
Rank 1
Richard asked on 23 Jul 2012, 05:17 AM

Hi team,

I recently ran into an issue, say I have an dropdownlist with in an telerik grid with ajax binding specified. This dropdownlist is actually defined in an template and referenced by an specific column using [UIHint("dropdown")]. It shows up whenever user click Edit button in the grid(in place edting) for that column. 

As the column represents Company which is all the same for every row, so I bind it right in the template cshtml file like below

@model FloMvc.Models.Company
@{List<FloMvc.Models.Company> list = (List<FloMvc.Models.Company>)ViewData["AvailableCompanies"];}

@(Html.Telerik().DropDownList()
.Name("CompanyList")
.BindTo(new SelectList(list, "Company_ID", "Name", (Model == null ? list.FirstOrDefault() : Model).Company_ID))
.ClientEvents(events => events.OnChange("onDropDownListChange"))

The data of company is popped up in the constructor of the controller, and the OnDropdownlistChange event is attached also. However, as this is ajax binding, so the template contains the dropdownlist would not get the selected model and thus cannot decide which is the selected item for the dropdown, so I did this by doing “Select()” method in "OnEdit" clientevent. Something like below -

$(e.form).find('#Employee').data('tDropDownList').select(function (dataItem) {
return dataItem.Text == e.dataItem['Employee'];

 Well, everything seems fine, so far. I can see when I clicked "Edit", the company dropdown is correctly behaved, correct list items, correct selected items. However, when I try to change the dropdown selection, the problem occurred.

* If I changed the selection to anything other than the first item(the item that was selected previously right before the select() method was executed), the "OnDropDownChange" event is not firing.

* When I click anywhere on the page other than the dropdownlist, the event triggered.

Can anybody please look into this?

thanks,

Richard

Tags
ComboBox
Asked by
Richard
Top achievements
Rank 1
Share this question
or