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

Grid Binding

2 Answers 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Manoj
Top achievements
Rank 1
Manoj asked on 11 Dec 2012, 06:27 AM
how to get the ID(Primary key) of the ProjectGroup model ? when i want to use that ID in the method like DataServiceFactory.AdminService.GetUsersForProjectGroup(ID) , i cant bind it , just for now to check, i passed ID as "1" in the below code . can any one help how to bind the "ID "

@(Html.Kendo().Grid(Model.ProjectGroups)
    .Name("Grid")
    .Columns(columns =>
                 {
                     columns.Template(@<div><h4>@item.Name</h4><small>@item.Description</small></div>).Title("Name");
                     List<User> users = DataServiceFactory.AdminService.GetUsersForProjectGroup(1);
                     columns.Template(
                         @<div>
                         @foreach(var user in users){<p>@user.FullName</p>}</div>).Title("Members");
                     List<Partition> partitions = DataServiceFactory.AdminService.GetAccessedPartitionForProjectGroup(1);
                     columns.Template(
                         @<div>
                         @foreach (var partition in partitions)
                         {<p>@partition.Name</p>}</div>).Title("Partitions");

                     columns.Template(@<a href="@Url.Action("EditGroup", new { ID = item.ID })"><i class="icon-pencil"></i></a>);
                      
                 })
                 .Pageable()
                 .Sortable()
    )

2 Answers, 1 is accepted

Sort by
0
Manoj
Top achievements
Rank 1
answered on 11 Dec 2012, 06:51 AM
Hello,
I am reposting the question to make it simple. I want to be able to make a server-side call using the Primary key (ID) of the item of the collection that is bound to the Grid. I am not able to figure out how to access it from within the template below. Where there is "1" below, I want to use something like @item.ID. 


@(Html.Kendo().Grid(Model.Products)
    .Name("Grid")
    .Columns(columns =>
                 {
                     columns.Template(@<div><h4>@item.Name</h4>
                     List<User> users = DataServiceFactory.AdminService.GetUsersForProjectGroup(1);
                      
                 })
0
Petur Subev
Telerik team
answered on 12 Dec 2012, 04:45 PM
Hello Manoj,

What you are trying to access is not possible. Why don't you use something like the code below:

.Columns(columns =>
{
    columns.Bound(c => c.PersonID);
    columns.Bound(c => c.Name).Template(@<text>
    @{
        var users = GetUsersCollectionItemsFromSomeWhere(item.PersonID);
    }
    @foreach(var u in users){
        @u.SomeProp
    }
        </text>);


Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Manoj
Top achievements
Rank 1
Answers by
Manoj
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or