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

Html Encode Not Encoding Double Quotes

1 Answer 576 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sravan
Top achievements
Rank 1
Sravan asked on 07 Dec 2012, 03:54 PM
In my rad Grid with a Grid Bound Column, If I have data for the Class Description like " Classes with capacity > 20 are considered as "full"" 
<telerik:GridBoundColumn UniqueName="ClassDescription" HeaderText="Class Description" HeaderStyle-Font-Bold="true"
                DataField="ClassDescription" HtmlEncode="true">
            </telerik:GridBoundColumn>
.When I use HtmlEncode="true" property for rad grid column, it is encoding  > with &gt; but not encoding the double quotes ("full"). 
When I tried using HttpContext.Current.Server.HtmlEncode in the server side it  is encoding > to &gt; and double quotes("full") to &quot;full&quot; successfully but HtmlEncode is not doing the same. 
How to fix this.

1 Answer, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 12 Dec 2012, 12:29 PM
Hello Sravan,

In order to resolve your issue you could use the provided code below. The idea is to subscribe to RadGrid ItemDataBound event and manually encode there. The reason for the experienced behavior is the HtmlEncode internally uses System.Web.HttpUtility.HtmlEncode method instead of Server.HtmlEncode.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    GridDataItem dataItem = e.Item as GridDataItem;
    if (dataItem != null)
    {
        dataItem["Name"].Text = Server.HtmlEncode(dataItem["Name"].Text);
    }
}


All the best,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Sravan
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Share this question
or