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

C# - How to Escape Hash (#) symbol in Grid Template When the Hash is in the Value Being Displayed?

2 Answers 485 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jim
Top achievements
Rank 1
Jim asked on 21 Oct 2013, 03:28 PM
Project Details:
ASP.NET MVC 4
Kendo UI Server Wrappers
C#
Twitter Bootstrap 2.3.2

We're the Kendo UI grid to show grouped results for our data.  Since we're using the server wrappers, one of the groups uses a Foreign Key column to show the value of a group instead of the id of the group.  I found a way to insert html into the group so that we can customize how it looks, and we're using the Bootstrap popover widget to display detail information when hovering over the group.  I found out that in our data, some of the values that will be displayed in the group contain the hash (#) symbol in it, which causes the kendo controls to give an error saying invalid template.  I know you can escape the hash with "\\", but this doesn't work correctly when trying to escape it in C# code.  If I do a ".Replace("#", "\\#"), what happens is it shows up in the grid like "\#Some more Text" instead of "#Some more Text".  How do we escape this in code?  The way I'm displaying the code is below:

C# Code:
GeneticModificationName = string.Format("{1} <span class='StrainDetailToolTipClass' data-placement='right' data-toggle='popover' data-content='<div>{0}</div>' title='Strain Description'><i class='icon-info-sign'></i></span>"
                + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style='color: #245fac; font-size: 10px !important; font-weight: bold;'>Genotype Order: ({2})</span>",
                ugStrain.Strain.Description != null ? Server.HtmlEncode(ugStrain.Strain.Description.Replace("#", @"\\#")) : "No Strain Description Available.",
                Server.HtmlEncode(ugStrain.Strain.Name.Replace("#", @"\\#")), sb.ToString())


Grid Column Snippet from Server Wrapper:
columns.ForeignKey(m => m.UserGroupStrainId, (System.Collections.IEnumerable)ViewData["Strains"], "StrainId", "GeneticModificationName").Title("Strain").Hidden();

2 Answers, 1 is accepted

Sort by
-1
Vladimir Iliev
Telerik team
answered on 23 Oct 2013, 12:05 PM
Hi Jim,

 
Current behavior is already discussed in several forum posts - I would suggest to check the following one where I already provide a solution:

Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jim
Top achievements
Rank 1
answered on 29 Oct 2013, 02:52 PM
Using a client template and javascript function to load the text seems to have worked.  Thanks.
Tags
Grid
Asked by
Jim
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Jim
Top achievements
Rank 1
Share this question
or