I have a kendo grid bound to a data source. I need to display a radio button column for the Primary key in the datasource.
My Datasource looks something like this
CountryID ,CountryName
1 , SomeCountryName1
2 , SomeCountryName2
Model
public class Country
{
public Country()
{
}
public int CountryID { get; set; }
public string CountryName { get; set; }
}
What is the right way of adding a radio button client template to the CountryID column. Also i need to obtain the selected Country ID
I managed to get the radio buttons but they don't seem to be working the way i want it to.
I need to get it working something like this.
The selection of radio button should highlight a single row and give back the ID
@(Html.Kendo().Grid<Mvc4SampleApplication.Models.Country>()
.Name("CountriesGrid2")
.EnableCustomBinding(true) // Enable custom binding
.Pageable(pager => pager
.PageSizes(true))
.Columns(columns =>
{
columns.Bound(o => o.CountryID).Width(200).ClientTemplate("<input type='radio' name='CountryID' value='#= CountryID #' />").Title("Select Country").HtmlAttributes(new { style = "text-align:center" });
columns.Bound(o => o.CountryName);
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Index2", "Address").Type(HttpVerbs.Get))
.Model(model =>
{
//The unique identifier (primary key) of the model is the ProductID property
model.Id(country => country.CountryID);
// Declare a model field and optionally specify its default value (used when a new model instance is created)
model.Field(country => country.CountryName).DefaultValue("N/A");
// Declare a model field and make it readonly
})
).Pageable(pager => pager
.PageSizes(true)).Sortable().Scrollable()
.Selectable(selectable => selectable.Enabled(true)
.Mode(GridSelectionMode.Single)
.Type(GridSelectionType.Row)).Events(events => events.Change(@<text>
function(e) {
//event handling code
alert("Hello");
}
</text>)))
My Datasource looks something like this
CountryID ,CountryName
1 , SomeCountryName1
2 , SomeCountryName2
Model
public class Country
{
public Country()
{
}
public int CountryID { get; set; }
public string CountryName { get; set; }
}
What is the right way of adding a radio button client template to the CountryID column. Also i need to obtain the selected Country ID
I managed to get the radio buttons but they don't seem to be working the way i want it to.
I need to get it working something like this.
The selection of radio button should highlight a single row and give back the ID
@(Html.Kendo().Grid<Mvc4SampleApplication.Models.Country>()
.Name("CountriesGrid2")
.EnableCustomBinding(true) // Enable custom binding
.Pageable(pager => pager
.PageSizes(true))
.Columns(columns =>
{
columns.Bound(o => o.CountryID).Width(200).ClientTemplate("<input type='radio' name='CountryID' value='#= CountryID #' />").Title("Select Country").HtmlAttributes(new { style = "text-align:center" });
columns.Bound(o => o.CountryName);
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Index2", "Address").Type(HttpVerbs.Get))
.Model(model =>
{
//The unique identifier (primary key) of the model is the ProductID property
model.Id(country => country.CountryID);
// Declare a model field and optionally specify its default value (used when a new model instance is created)
model.Field(country => country.CountryName).DefaultValue("N/A");
// Declare a model field and make it readonly
})
).Pageable(pager => pager
.PageSizes(true)).Sortable().Scrollable()
.Selectable(selectable => selectable.Enabled(true)
.Mode(GridSelectionMode.Single)
.Type(GridSelectionType.Row)).Events(events => events.Change(@<text>
function(e) {
//event handling code
alert("Hello");
}
</text>)))