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

[Solved] Settig Cell.Text to HTML?

2 Answers 136 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.
James Davies
Top achievements
Rank 1
James Davies asked on 05 Apr 2010, 06:04 PM
Hi,

I used to be able to set Cell.Text in a CellAction to some custom HTML, e.g. <img ...>, but now the grid seems to encode the HTML - is there a way around this please?

We're using 'Telerik\Extensions for ASP.NET MVC Q1 2010'.

Many thanks,
Jim

2 Answers, 1 is accepted

Sort by
0
Accepted
Mattias
Top achievements
Rank 2
answered on 06 Apr 2010, 08:13 AM
You could make an server or client side template.
<%= Html.Telerik().Grid<Customer>() 
        .Name("Grid") 
        .Columns(columns => 
        { 
            columns.Bound(c => c.CustomerID) 
                .ClientTemplate("<img alt='<#= CustomerID #>' src='"  
                    + Url.Content("~/Content/Grid/Customers/")  
                    + "<#= CustomerID #>.jpg' />") 
                .Title("Picture"); 
            //omitted for brevity 
        } 
%> 
<% Html.Telerik().Grid(Model) 
        .Name("Grid") 
        .Columns(columns =>  
        { 
            //Template column. The grid displays the HTML defined by the argument. 
            columns.Template(c => { 
            %> 
                <img  
                    alt="<%= c.CustomerID %>"  
                    src="<%= Url.Content("~/Content/Grid/Customers/" + c.CustomerID + ".jpg") %>"  
                  /> 
            <
            }); 
            //Regular databound column. The grid displays the value of the CustomerID property. 
            columns.Bound(c => c.CustomerID); 
        }) 
        .Render(); 
 %> 

Read more on the Telerik demos
0
James Davies
Top achievements
Rank 1
answered on 06 Apr 2010, 11:07 AM
Many thanks Mattias.

I was trying to use a server-side template to call an Html extension returning HTML like "<img src=... >" to show a tick mark, and I had trouble getting the <% syntax right (not the first time!).

For anyone interested, I ended up with something like:

 

columns.Add(u => u.UserName).Title("Name");  
 
columns.Template(u => { %> <%= Html.ShowCheckBox("enabled", u.UserEnabled)%> <% })  
 
    .Title("Enabled");  
 
columns.Template(u => { %> <%= Html.ShowCheckBox("administrator", u.UserAdministrator)%> <% })  
 
    .Title("Administrator");  
 
columns.Add(u => u.UserNotes).Title("Notes");  
 
 

which works fine, and is simpler than using CellAction was

Regards,
Jim

 

Tags
Grid
Asked by
James Davies
Top achievements
Rank 1
Answers by
Mattias
Top achievements
Rank 2
James Davies
Top achievements
Rank 1
Share this question
or