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

DropDownList On Demand Selected Value Issue

2 Answers 133 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.
Justin
Top achievements
Rank 1
Justin asked on 08 Mar 2011, 10:17 PM
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:
<%@ 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

2 Answers, 1 is accepted

Sort by
0
Justin
Top achievements
Rank 1
answered on 14 Mar 2011, 02:57 PM
Nevermind. I found a solution using the regular dropdownlist instead of telerik.
0
Ali
Top achievements
Rank 1
answered on 14 Oct 2011, 05:12 PM
can you give me code exp. how you did that.

Thanks
Tags
ComboBox
Asked by
Justin
Top achievements
Rank 1
Answers by
Justin
Top achievements
Rank 1
Ali
Top achievements
Rank 1
Share this question
or