0

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

2 Answers 2

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
}
Sign up to request clarification or add additional context in comments.

8 Comments

@ArunGupta Do you need any more help with this question?
Hey Nick, Thanks for your reply, but still i am facing issue with image binding, since i am using partial view and i am paasing image path which is in my local machine that time, its thrwoing error like invalid arguments. could you please post a working code which has bind with any image for MVC ASPX engine.
@ArunGupta I have added an example with bindings. Is this what you are looking for?
yes this is my requirement, but when i am trying this its not bind image, its just displaying column value which is coming from viewModel.
I added a sample for implementing this using client templates. Try this. You mentioned you wanted a 'static' image, which is why I provided the first few samples.
|
0

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)

Comments

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.