0

I want to add an image to a data grid column, I am using telerik grid for this, however I get the following error, its on Line 51:

Compiler Error Message: CS1525: Invalid expression term ')'

Source Error:

Line 49:     column.Bound(o => o.HoursWorked).Title("Hours");
Line 50:     column.Template(o =>
Line 51:     {%>
Line 52:     <img src="/Content/img/delete.png" alt="Delete" title="Delete"/>
Line 53:     <%

Here is how I am trying to add an image to the column:

<div>
<%=Html.CustomGridFor("Hours", "WorkHours", "HoursWorked", GridOptions.EnableSelecting, Model).Columns(column =>
   {
     column.Bound(o => o.DateWorked).Title("Date").Width("65px");
     column.Bound(o => o.Description).Title("Description").Width("120px");
     column.Bound(o => o.HoursWorked).Title("Hours");
     column.Template(o =>
     {%>
     <img src="/Content/img/delete.png" alt="Delete" title="Delete" onclick="javascript:deleteHours();" />
     <%
     }).Title("").ClientTemplate(
     "<img src=\"/Content/img/delete.png\" alt=\"Delete\" title=\"Delete\"/>"
     ).Width(15);
     }).HtmlAttributes(new { style = "width: 270px;" });
     %>
</div>

Tried this too:

<div>
<%=Html.CustomGridFor("Hours", "WorkHours", "HoursWorked", GridOptions.EnableSelecting, Model).Columns(column =>
   {
     column.Bound(o => o.DateWorked).Title("Date").Width("65px");
     column.Bound(o => o.Description).Title("Description").Width("120px");
     column.Bound(o => o.HoursWorked).Title("Hours");

        column.Template(o =>
        {
        %>
            <img 
                alt="Delete" 
                src="/Content/img/delete.png" 
              />
        <%
        });

</div>
2
  • 1
    Is there a reason you're using a client and server template? I think this demo is almost exactly what you want, just use your delete image instead: demos.telerik.com/aspnet-mvc/grid/templatesserverside Commented Oct 15, 2012 at 16:08
  • @Jisaak I tried the way suggested in demo you provided, still get the same error about invalid expression term ')'. I have updated my code above Commented Oct 16, 2012 at 22:57

1 Answer 1

1

Try to use this:

<div>
<%=Html.CustomGridFor("Hours", "WorkHours", "HoursWorked", GridOptions.EnableSelecting, Model).Columns(column =>
        {
           column.Bound(o => o.DateWorked).Title("Date").Width("65px");
           column.Bound(o => o.Description).Title("Description").Width("120px");
           column.Bound(o => o.HoursWorked).Title("Hours");
           column.Template(o => string.Empty).Title("")
                 .ClientTemplate(
                      "<img src=\"/Content/img/delete.png\" alt=\"Delete\" title=\"Delete\"/>")
                 .Width(15);
        }).HtmlAttributes(new { style = "width: 270px;" });
%>
</div>
Sign up to request clarification or add additional context in comments.

4 Comments

I was still getting the error: Compiler Error Message: CS1525: Invalid expression term ')' Removing ";" from the last line does add another column with no heading, but still dont see the delete image.
Could you show what is html in client that is generated in this column with no heading?
This is what I see: <TD class=t-last></TD>
I got it to work this way: column.Template(o => { %> <img src="/Content/img/delete.png" alt="Delete" title="Delete")" /> <% }).Title("").ClientTemplate( "<img src=\"/Content/img/delete.png\" alt=\"Delete\" title=\"Delete\"/>") .Width(25).HtmlAttributes(new { style = "text-align: center;" }); }).Render(); And removing the "=" from first line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.