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

Master/Detail Grid problem

7 Answers 185 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 22 Jul 2013, 09:34 AM
Hi there,

I am having some problems to create a Master/Detail Grid on ASP.NET MVC
The connection to the SQL Database is created with Linq-to-sql, so I have the model. I have created two functions in the controller to get the data from the DB.

I am following the example shown here: http://demos.kendoui.com/web/grid/hierarchy.html
but is not working :/

here is my ASPX code:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master"  Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <h3>Users</h3>
<br />
<%: Html.Kendo().Grid<PaysmardService.Models.Users>("Users")
            .Name("grid")
            .Columns(columns =>
            {
                columns.Bound(e => e.FirstName).Width(110);
                columns.Bound(e => e.LastName).Width(110);
                columns.Bound(e => e.Country).Width(110);
                columns.Bound(e => e.City).Width(110);
                columns.Bound(e => e.Title);

            })
            .Sortable()
            .Pageable()
            .Scrollable()
            .ClientDetailTemplateId("template")
            .HtmlAttributes(new { style = "height:430px;" })
            .DataSource(dataSource => dataSource
                .Server()
                .PageSize(6)
                .Read(read => read.Action("Users", "Home"))
            )
            .Events(events => events.DataBound("dataBound"))
    %>

    <script id="template" type="text/kendo-tmpl">
        <%: Html.Kendo().Grid<PaysmardService.Models.Phones>("Phones")
                .Name("grid_#=ID#")
                .Columns(columns =>
                {
                    columns.Bound(o => o.PhoneNumber ).Width(100);
                    columns.Bound(o => o.IsBlocked ).Width(110);
                    columns.Bound(o => o.IsEnabled);
                    columns.Bound(o => o.DeviceType ).Width(200);
                })
                .DataSource(dataSource => dataSource
                    .Server()
                    .PageSize(5)
                    .Read(read => read.Action("Phones", "Home", new { ID = "#=ID#" }))
                )
                .Pageable()
                .Sortable()
                .ToClientTemplate()               
        %>
    </script>
    <script>
        function dataBound() {
            this.expandRow(this.tbody.find("tr.k-master-row").first());
        }
    </script>
</asp:Content>


here is my controller code:
        /////////////Phones/////////////
        public ActionResult Phones(int id)
        {
            _context = new DCPaysmardServiceDataContext();
            ViewData["Phones"] = _context.Phones.Where(phones => phones.UserFk == id);
            return View();
        }

        /////////////Users/////////////
        public ActionResult Users()
        {
            _context = new DCPaysmardServiceDataContext();
            ViewData["Users"] = _context.Users;

            return View();
        }


and the model is being created with the Linq-to-Sql.

I have tried everything .. but I dont get the selection button and the detail.
It would be very nice if you can give me a hand.

Thanks in advance.




7 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 23 Jul 2013, 06:30 AM
Hello Patrick,

You have mixed two types of implementation of Grid hierarchy. Depending of the way the Grid is bound you can have server hierarchy (with server implementation of the detail template) and ajax hierarchy with client detail template. The following articles shows how to implement both:

 - Ajax Hierarchy
 - Server Hierarchy

Regards,
Nikolay Rusev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Patrick
Top achievements
Rank 1
answered on 23 Jul 2013, 09:30 AM
Hi Nikolay,

thank you very much for your answer! 

I found this sample yesterday  server-detail-template and I've been trying to make it work.
I have implemented it as the article say (I have only changed the information I need pointing to the tables and fields in my DB)

- I created the ADO.NET Entity Data Model
- then wrote the code for the actionResult on the Controller to get the data
- and finally I wrote the code for getting the grid on the ASPX page.
but I still have a problem with the .DetailTemplate.

Do you have any idea what happens here? 

Thank you very much in advance!
Antonio.


0
Patrick
Top achievements
Rank 1
answered on 23 Jul 2013, 09:31 AM
Hi Nikolay,

thank you very much for your answer! 

I found this sample yesterday  server-detail-template and I've been trying to make it work.
I have implemented it as the article say (I have only changed the information I need pointing to the tables and fields in my DB)

- I created the ADO.NET Entity Data Model
- then wrote the code for the actionResult on the Controller to get the data
- and finally I wrote the code for getting the grid on the ASPX page.
but I still have a problem with the .DetailTemplate.

Do you have any idea what happens here? 

Thank you very much in advance!
Antonio.


0
Patrick
Top achievements
Rank 1
answered on 23 Jul 2013, 10:09 AM
Hello Nikolay, I tried that, but is not working.
0
Patrick
Top achievements
Rank 1
answered on 23 Jul 2013, 10:19 AM
Hi Nikolay, sorry for writing the comment like that, but I get an error if I write it with a format :/ thanks in advance.
0
Patrick
Top achievements
Rank 1
answered on 23 Jul 2013, 11:32 AM
Hi again Nikolay ;) I think I got it. but... one more question, can I edit data?.. Cause I have tried it, but it seems that with this kind of solution there is no way to do it.. or is it possible?
0
Nikolay Rusev
Telerik team
answered on 25 Jul 2013, 06:59 AM
Hello Patrick,

What exactly is the issue with editing? In the distribution files that you've downloaded there are examples (\wrappers\aspnetmvc\Examples\Areas\razor\Views\web\grid) demonstrating server editing (serverediting.cshtml) and server hierarchy(serverhierarchy.cshtml).

You can combine those two example for server hierarchy with editing.

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