I have a ListBox with a Row Template that contains a Button. There is no guarantee that the user will press the button for the "selected" item in the ListBox. So, I need to capture the Data Item in the ListBox that is related to the button that was pressed. How do I accomplish this?
Thanks for your help,
Joel
Note: My goDetail script currently just grabs the listBox control and posts for the selected item. It doesn't post based on the Row that contained the Button that fired the event.
<
div
class
=
"container"
>
@(Html.Kendo().ListBox()
.Name("listBox")
.DataTextField("Name")
.DataValueField("Id")
.DataSource(source =>
source.Read(read =>
read.Action("IndexJson", "SessionOptionTemplates").Data("gridGetData"))
)
.TemplateId("item-template")
.Toolbar(toolbar =>
{
toolbar.Position(ListBoxToolbarPosition.Right);
toolbar.Tools(tools => tools
.MoveUp()
.MoveDown()
.Remove()
);
})
.Events(events => events
.Reorder("onReorder")
.Remove("onRemove"))
.HtmlAttributes(new { style = "height:550px;width:530px" })
.BindTo(new List<
SessionOptionTemplate
>()))
</
div
>
</
div
>
</
div
>
<
script
id
=
"item-template"
type
=
"text/x-kendo-template"
>
<
span
><
input
type
=
"submit"
value
=
"Details"
class
=
"btn"
onclick
=
"goDetail()"
style
=
"margin:5px"
/></
span
>
<
span
class
=
"k-state-default"
style
=
"margin-left:10px"
><
h5
>#: data.Name #</
h5
><
p
>#: data.Description != null ? data.Description : '' #</
p
></
span
>
</
script
>
function goDetail(e) {
//alert("goDetail");
var listbox = $("#listBox").data("kendoListBox");
var element = listbox.select();
var dataItem = listbox.dataItem(element[0]);
var url = '@Url.Action("Details", "SessionOptionTemplates")?id=' + dataItem.Id + '@Model.GetUrlParameters()';
// Replace & with & as the above encoding step changes & to &.
window.location.href = url.replace(/&/g, "&");
}