RadGrid Column Being Displayed Empty If Its Contains Special Characters

Telerik’s Radgrid is a wonderful way to show all of your data but sometime something happens, which we never ever expected like RadGrid Column Being Displayed Empty If Its Contains Special Characters

My case was that I need to show xml on the rad grid but rad grid displaying column all empty(No clue, what was happening wrong) only for single column which had xml rest was working fine without any problem.

I checked through firebug that there might be an issue with Jquery or similar stuff but everything was working fine.

On that moment, I had no any Idea why its happening?, Suddenly I got an Idea in my mind that we can use http utility  to decode and incode the xml, I was not sure that, it will work or not, but that the last hope I left.

So what I did, I tried the following code for .aspx page

<telerik:GridTemplateColumn HeaderText="Stack" UniqueName="Stack" DataField="Stack" SortExpression="Stack" HeaderStyle-Width="200px" >
     <ItemTemplate>
       <%# Server.HtmlEncode((string)DataBinder.Eval(Container.DataItem, "Stack")) %>
     </ItemTemplate>
  </telerik:GridTemplateColumn>

And same I tried the following code for .aspx.cs page

 if (e.Item is GridDataItem)
  {
      var item = (GridDataItem)e.Item;
      item["Stack"].Text = HttpUtility.HtmlEncode("<Your> <Xml> <Here>");
  }
      

And this time, above method worked when I again tried to run. Finally issue has been fixed (whew) 😉
Hope you will like this

Leave a Reply