将图像添加到telerik数据网格列

时间:2012-10-12 21:01:01

标签: asp.net-mvc telerik-grid telerik-mvc

我想将图像添加到数据网格列,我正在使用telerik网格,但是我得到以下错误,它在第51行:

编译器错误消息:CS1525:无效的表达式术语')'

来源错误:

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:     <%

以下是我尝试将图像添加到列中的方法:

<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>

也试过这个:

<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>

1 个答案:

答案 0 :(得分:1)

尝试使用它:

<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>