This question is locked. New answers and comments are not allowed.
Hi, I am using the DropDownList as a user control and it is set to load on demand. I have a client event for "OnLoad" which fills the DropDownList whenever it is loaded on a page. This works fine. The issue occurs when I use the user control as a UIHint for a property on the grid. When the grid is edited, it tries to set the selected value of the dropdownlist, but the OnEdit of the grid and the OnLoad of the DropDownList seem to have issues. The selected value does not work. I tried calling the fill method in the OnEdit method, but then it gets called twice and the dropdownlist shows a loading icon the whole time. Any ideas on a workaround for this?
Here is some example code:
The User control:
The property in the grid:
The onEdit for the grid:
And this is also used in a partial view outside of a grid:
Thanks.
Justin
Here is some example code:
The User control:
<%@ Control Language=
"C#"
Inherits=
"System.Web.Mvc.ViewUserControl<string>"
%>
<%: Html.Telerik().DropDownList()
.Name(
"LevelOfCompetence"
)
.HtmlAttributes(
new
{ style =
"width: 80%;"
})
.DataBinding(binding => binding.Ajax()
.Select(
"PopulateDropDown"
,
"LevelOfCompetence"
,
new
{ selectedText = Model }))
.ClientEvents(e => e.OnLoad(
"ddl_onLoad"
))
%>
The property in the grid:
[UIHint(
"LevelOfCompetenceDropDownList"
)]
[DisplayName(
"Level of Competence"
)]
[Required]
[Range(1, Int32.MaxValue, ErrorMessage =
"The field Level of Competence is required."
)]
public
string
LevelOfCompetence {
get
;
set
; }
The onLoad for the dropdownlist:
function
ddl_onLoad() {
$(
this
).data(
'tDropDownList'
).fill();
}
The onEdit for the grid:
function
tti_onEdit(e) {
if
(e.mode ==
'edit'
) {
$(e.form).find(
'#LevelOfCompetence'
).data(
'tDropDownList'
).select(
function
(dataItem) {
return
dataItem.Text == e.dataItem[
'LevelOfCompetence'
];
});
}
}
And this is also used in a partial view outside of a grid:
@Html.EditorFor(task => task.LevelOfCompetence)
Thanks.
Justin