How do I include and populate a ComboBox inside a Grid template? I have it list my Templates successfully as defined. But, I need a ComboBox that lists the Template's Items. The data is served up from the Model.
Then, on selection of the items in the ComboBox, I need to store the Item index to a local array/list (because we don't know how many templates there are) for consumption on a button press.
Template:
public partial class SessionOptionTemplate
{
public int Id { get; set; }
[MaxLength(50)]
public string Name { get; set; }
[MaxLength(128)]
public string Description { get; set; }
public int Order { get; set; }
public DateTime AddTimestamp { get; set; } = DateTime.UtcNow;
public DateTime? DeactivateTimestamp { get; set; }
public ICollection<
SessionOptionItem
> SessionOptionItems { get; set; } = new HashSet<
SessionOptionItem
>();
}
Items:
public partial class SessionOptionItem
{
[Key]
public int Id { get; set; }
public int SessionOptionTemplateId { get; set; }
[MaxLength(50)]
public string Name { get; set; }
[MaxLength(128)]
public string Description { get; set; }
public DateTime AddTimestamp { get; set; } = DateTime.UtcNow;
public DateTime? DeactivateTimestamp { get; set; }
}
Grid:
@(Html.Kendo().Grid((IEnumerable<
SessionOptionTemplate
>)Model.SessionOptionTemplates)
.Name("template-grid")
.HtmlAttributes(new { @class = "GridNoHeader" })
.Columns(columns =>
{
columns.Template(" ").Title("Name").Width(200);
})
.ClientRowTemplate(@"
<
div
style
=
'margin-bottom: 10px;'
>
<
input
class
=
'select'
type
=
'checkbox'
#=IsSelected ? " + @"
checked
=
'checked'
" + @" : '' # />
<
span
class
=
'name'
>#: Name #</
span
><
br
/>
<
span
class
=
'desc'
>#: Description #</
span
>
</
div
>")
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.ServerOperation(false))
)