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

[Solved] Interpret embed databound expressions outside of the ClientRowTemplate

3 Answers 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jeffrey
Top achievements
Rank 1
Jeffrey asked on 14 May 2012, 03:11 PM
Below is a simplified version of a view I am working with.  What I want to do is shown in the comments about half way down:

//I want back what the pid is, such as: filepath = "App_Data/123456789/";
//but comes back as: filepath = "App_Data/<#= pid #>/"
//Html.Encode(filepath) does display correct, but I need to find each file here
//for each id, so that I may find all file for that individual

<% Html.Telerik().Grid<UCHonorsProg.Models.usr_StudentInfo_Result>()
            .Name("Students")
            .DataBinding(dataBinding => dataBinding.Ajax()
                    .Select("StudentProgGrid", "Home"))
            .Columns(c => c.Bound(o => o.FullName).Title("Full Name"))
            .DetailView(detailView => detailView.ClientTemplate(
                Html.Telerik().TabStrip().Name("<#= StudentID #>").Items(item =>
                                 {
                        item.Add().Text("Required Courses").Content(
                        Html.Telerik().Grid<UCHonorsProg.Models.usr_Courses_Result>()
                                 .Name("Required_<#= StudentID #>")
                                 .DataKeys(keys => keys.Add(m => m.pid))
                                 .DataBinding(dataBinding => dataBinding.Ajax()
                                 .Select("Courses", "Home", new { pId = "<#= pid #>" }))
                                 .Columns(columns => columns.Bound(o => o.primkey))
                                 .ToHtmlString()
                        );
                        %>
                        <%  var x = "<#= pid #>";
                            var filepath = "App_Data/" + x + "/";
                            //I want back what the pid is, such as: filepath = "App_Data/123456789/";
                            //but comes back as: filepath = "App_Data/<#= pid #>/"
                            //Html.Encode(filepath) does display correct, but I need to find each file here for each id
                       %>
                        <%  item.Add().Text("Projects").Content(
                            Html.Telerik().Grid<UCHonorsProg.Models.usr_Projects_Result>()
                                .Name("Projects_<#= StudentID #>")
                                .DataKeys(keys => keys.Add(m => m.primkey))
                                .Columns(columns => columns.Bound(o => o.primkey))
                            .ClientRowTemplate(grid =>
                                        "<div class=\"ProjectGrid\"><table><tr><th>Filename</th></tr>" +
                                            "<tr><td>" + Html.Encode(filepath) + "</td></tr></table></div>"
                                        )
                                        .DataBinding(dataBinding => dataBinding.Ajax()
                                .Select("Projects", "Home", new { pId = "<#= pid #>" })
                                )
                            .ToHtmlString()
                            );
                            }).SelectedIndex(0).ToHtmlString())).Render();
    %>

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 17 May 2012, 03:44 PM
Hello Jeffrey,

I am not sure if I understand correctly the exact scenario. Could you provide more information about how do you want to use the filepath in the row template?

Greetings,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Jeffrey
Top achievements
Rank 1
answered on 17 May 2012, 04:36 PM
Thanks for looking at this.

I need each pid to come through, since each individual within the grid has their own folder.  I need the filepath to come through as:
(example where the pid = 123456789 ---> "App_Data/123456789/")

var mypid = "<#= pid #>";
var filepath = "App_Data/" + mypid + "/";
//so that
//filepath = "App_Data/123456789/";
//not, as it comes through now as:
//filepath = "App_Data/<#= pid #>/";

this will go within the code block (it works if I hard code it as: filepath = "App_Data/123456789/";):
    var mypid = "<#= pid #>";
    var path = Path.Combine(Server.MapPath("~/App_Data"), mypid);
    var filepath = "App_Data/" + mypid + "/";
    foreach (var fileitem in Directory.GetFiles(path).Select(file => new FileInfo(file)))
    {
        filename = Path.GetFileName(fileitem.Name);
        filesize = fileitem.Length >= 1024 ? fileitem.Length / 1024 + " kilobytes" : fileitem.Length + " bytes";
        if (filename != null) path2 = Path.Combine(filepath, filename);
    }

This will then drop these Files in the ClientRowTemplate see highlighted area of screenshot
0
Daniel
Telerik team
answered on 22 May 2012, 07:49 AM
Hello again Jeffrey,

The "pid" parameter won't be evaluated if it is not a property of the Model of the Grid that uses the row template because it will be in different context. Also in Ajax binding, the data is loaded on the client so the files for a particular ID can't be found in the detail template which is serialized and loaded on demand. This can be achieved when using Server Details. In Ajax binding you could either include the file paths in the Detail Grid model or call function inside the detail which to make an Ajax request for the correct file paths and insert them in the row in the success callback.

Kind regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Grid
Asked by
Jeffrey
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Jeffrey
Top achievements
Rank 1
Share this question
or