How to bind images in Telerik Grid for ASP.NET MVC

柔情痞子 提交于 2019-12-25 07:49:13

问题


Please let me know how to bind a image static image with all rows in Telerik Grid for ASP.NET MVC.

 <%= Html.Telerik().Grid(Model.SearchResponse)
               .Name("SearchGrid")
               .Columns(columns =>
                   {
                       //Here i need to bind a static image column//

                       columns.Bound(grid => grid.Name);
                       columns.Bound(grid => grid.CaseNumber);
                     })
                   .Pageable(true)
    %>

回答1:


This is possible by adding another templated column to your collection:

Using ASPX

columns.Template(c => { 
%><img alt="Static Image Alt Text" src="<%= Url.Content("~/myImage.jpg") %>" 
/><% 
}).Title("Static Image");

Using Razor

columns.Template(
   @<text>
     <img alt="Static Image Alt Text" src="@Url.Content("~/myImage.jpg") " />
  </text>
).Title("Static Image");

UPDATE: If you wish to bind images from your model, please refer to the following example:

columns.Template(c => {
%>
<img 
alt="<%= c.CustomerID %>" 
src="<%= Url.Content("~/" + c.CustomerID + ".jpg") %>" 
/>
<%
});

Or if you're using client templates, try the following:

.Columns(columns =>
{
columns.Bound(c => c.CustomerID)
.ClientTemplate("<img alt='<#= CustomerID #>' src='" 
+ Url.Content("~/") 
+ "<#= CustomerID #>.jpg' />")
.Title("Picture");
//omitted for brevity
}



回答2:


This way we can bind image with every row. we can also add Action with these images.

columns.Command(commands => commands.Custom("View").ButtonType(GridButtonType.BareImage)


来源:https://stackoverflow.com/questions/9098436/how-to-bind-a-image-column-in-mvc-telerik-radgrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!