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

[Solved] Emded html in grid cell

8 Answers 135 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.
Marc Simkin
Top achievements
Rank 2
Iron
Iron
Veteran
Marc Simkin asked on 16 Jun 2011, 02:08 PM
How can I place HTML in a cell in the grid.  I'm don't need a control like a check box or a drop down.
I'm look to simple html that might consist of <p>, <li>, or <br> to name a few.

If I can't have HTML in the cell, will the cell be able to process the a standard carriage return/line feed indicator?

thanks

marc

8 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 16 Jun 2011, 02:17 PM
Hello Marc Simkin,

 You can display HTML by setting the Template of the column (or ClientTemplate) if you are using ajax binding.

columns.Bound( c => c.Name).Template(c => 
{
%>
     <strong><%= c.Name%></strong>
<%
}).ClientTemplate("<strong><#= Name #></strong>");

Regards,

Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Marc Simkin
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 16 Jun 2011, 02:55 PM
Hi:

Thank you for the quick response.

It would be the client template, since the data needs to be bound in the browser.

When I try to bind the data field with the razor syntax, all I get is the field name.  I've tried the fieldname with and without quotation marks.
The field in question is called QuestionChoices.

My grid defination is below, anythoughts on what I'm doing wrong.
Please let me know if I need to upload the code.

marc
@(Html.Telerik().Grid<ClientGridTest.Models.ProfileItem>()<BR>   
.Name("ProfileGrid")<BR>    .Columns(columns
=><BR>           
{<BR>               
columns.Bound(o =>
o.FieldName).Title("Name");<BR>               
columns.Bound(o =>
o.FieldOrder).Title("Order");<BR>               
columns.Bound(o =>
o.FieldType).Title("Type");<BR>               
columns.Bound(o => o.BaseProfileField).Title("Base
Profile?")<BR>                   
.ClientTemplate("<input type='checkbox' name='chkBase' <A href="mailto:value='@BaseProfileField'">value='@BaseProfileField'</A>
/>");<BR>               
columns.Bound(o =>
o.FieldDeleted).Title("Deleted?")<BR>                   
.ClientTemplate("<input type='checkbox' name='chkDeleted' <A href="mailto:value='@FieldDeleted'">value='@FieldDeleted'</A>
/>");<BR>               
columns.Bound(o =>
o.FieldRequired).Title("Required?")<BR>                   
.ClientTemplate("<input type='checkbox' name='chkRequired' <A href="mailto:value='@FieldRequired'">value='@FieldRequired'</A>
/>");<BR>               
columns.Bound(o =>
o.FieldDescription).Title("Description");<BR>               
columns.Bound(o => o.QuestionChoices).Title("Question
Choices")<BR>                   
.ClientTemplate(@QuestionChoices);<BR>           
}<BR>    )<BR>    .ClientEvents(events =>
events<BR>       
.OnDataBinding("onDataBinding")<BR>       
.OnRowDataBound("onRowDataBound")<BR>    )<BR>   
.Scrollable(scrolling => scrolling.Height(400))<BR>)<BR>

0
Dimo
Telerik team
answered on 16 Jun 2011, 02:59 PM
Hi Marc,

The HTML markup inside the client templates is not valid and I am not sure whether this is how you are using it, or it has been broken when you pasted it here. Please provide the Grid declaration again and make sure it is exactly the same as in your project. Thanks.

By the way, have you checked our Razor online demos?

http://demos.telerik.com/aspnet-mvc/grid/templatesclientside

Greetings,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Marc Simkin
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 16 Jun 2011, 03:06 PM
I have attached my sample project below, this way you can see what I'm trying to do. The view is in Views/Home/Index.cshtml.  The controller is in Controllers/HomeController.cs.

I'm populating the collection of items in the controller.  If you look, the second item has some embedded HTML.

Thank you for the help.

marc
0
Dimo
Telerik team
answered on 16 Jun 2011, 03:41 PM
Hi Marc,

If you view the page source and inspect the value of the profileItems variable, you will see that the HTML tags come from the datasource. Moreover, currently the last column has no enabled client template at all.

Best wishes,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Marc Simkin
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 16 Jun 2011, 03:45 PM
Hi, I know all that.  My question still stands.  How can I bind the value of the column in the data source to the grid so that it displays the embedded HTML?

The few things I tried either made no difference, displayed the data source column name, or ended up displaying nothing.

I'm looking to your team for guidence as to what is the best way of achieving what I need.

Do I need to embedded a html literal control in the last column?

thanks

marc
0
Accepted
Dimo
Telerik team
answered on 16 Jun 2011, 03:57 PM
Oh, in this case set  .Encoded(false) to the column.

Greetings,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Marc Simkin
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 16 Jun 2011, 03:59 PM
Hi, thank you.

That was the solution.
marc
Tags
Grid
Asked by
Marc Simkin
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Atanas Korchev
Telerik team
Marc Simkin
Top achievements
Rank 2
Iron
Iron
Veteran
Dimo
Telerik team
Share this question
or