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

[Solved] Error when adding template column

1 Answer 147 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.
Steve
Top achievements
Rank 1
Steve asked on 12 Aug 2010, 03:52 PM
Not sure why this is happening, but when I try to add the following template column to my grid, I get the error:
Compiler Error Message: CS1525: Invalid expression term ')'
Line 59:         columns.Command(commands => { commands.Edit(); } ).Width("12%");
Line 60:         columns.Template(o => 
Line 61: {Line 62:               %>
Line 63:                   <%= Html.ActionLink("Edit", "Home", new { id = o.ProductId }) %>

Here is my code:

<%= Html.Telerik().Grid(Model.ProductTemplateList)
    .Name("Grid").HtmlAttributes(new { style = "width:90%;" })
    .DataKeys(keys => keys.Add(c => c.ProductId))
    .DataBinding(dataBinding => dataBinding.Server()
    .Select("Edit", "ProductTemplate"))
    .Columns(columns =>
    {
        columns.Command(commands => { commands.Edit(); } ).Width("12%");
        columns.Template(o =>
          {
              %>
                  <%= Html.ActionLink("Edit", "Home", new { id = o.ProductId }) %>
              <%
          }).Title("Edit");        
        columns.Bound(o => o.ProductId).Width("7%").Title("ID");
        columns.Bound(o => o.ProductName).Width("15%").Title("Name");
        columns.Bound(o => o.Product_Description).Width("35").Title("Description");
        columns.Bound(o => o.ProductCategory.ProductCategoryName).Width("10%").Title("Category");
        columns.Bound(o => o.ControlPlanId).Width("8%").Title("Plan ID");
        columns.Bound(o => o.Status).Width("8%").Title("Status");
        columns.Bound(o => o.DateTimeAdded).Width("15%").Title("Created Date").Format("{0:MM/dd/yyyy}");        
    })

    .Filterable()
    .Pageable()
    .Scrollable()
    .Sortable();
    %>  

I have set up the web.config and site.master correctly and I have no problem displaying the grid and Model data when I exclude the template column. It's only when I add the template column, I get the error. Can someone help me see what I may be missing?

1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 12 Aug 2010, 04:06 PM
Hi Steve,

The error is caused because the template that you are specifying breaks the <%= %> code block. Use the <% %> code block and call .Render() at the end of the grid declaration, like this:
<% Html.Telerik().Grid(Model.ProductTemplateList)
   .Name("Grid").HtmlAttributes(new { style = "width:90%;" })
    
   /* ... */

   .Sortable()
   .Render();
%>


Regards,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Share this question
or