Reputation: 850
I have a grid with dropdown and a checkbox. Whenever I have checked the checkbox (multi-select) I want to get the value of the drop downlist that is selected. How can I do that using kendoui.
Please help me here is my fiddle.
And my code:
<div id="grid"></div>
<input type="button" value="gridSelectedItem" onclick="selectElementContents( document.getElementById('grid') );"
/>
<div>
<input id="dropdownList" runat="server" /></div>
<script type="text/x-kendo-template" id="CheckboxTemplate">
<li unselectable="off" class="k-item nowrap check-item">
<input type="checkbox" name="#= text #" value="#= value #" class="check-input" #= selected ? "checked" : "" #/>
<span>#= text #</span>
</li>
Upvotes: 1
Views: 13417
Reputation: 294
<div class="form-group">
<label>Shift</label>
<div class="input-group">
@(Html.Kendo().DropDownListFor(t => t.ShiftId)
.Name("ShiftId")
.DataTextField("Text")
.DataValueField("Value")
.OptionLabel("...Select Shift...")
.DataSource(source => source.Read(read => read.Action("GetShifts", "AssessmentResult")))
.HtmlAttributes(new { style = "width:292px", @required = "required" })
)
</div>
</div>
<button type="button" id="show">Show</button>
<script type="text/JavaScript">
$('#show').click(function(event) {
var ShiftId = $("#ShiftId").data("kendoDropDownList").value();
alert(ShiftId);
}
Upvotes: 0
Reputation: 4209
This does it for me:
var selectedId = $('#MyDropDown').data("kendoDropDownList").value();Upvotes: 5
Reputation: 20203
On a side not - The template that you have defined does not need to contain li element - it is generated automatically for you.
To retrieve the model related to the item you can use the dataItem method of the ddl client object and the index of the option(that's why you need to fix your template because the index will be wrong).
Here is the magical snippet:
var ddl = $('#dropdownList').data().kendoDropDownList;
var model = ddl.dataItem($input.closest('.k-item').index());
alert(model.text);
I updated your fiddle to see it in action.
Upvotes: 8