Search code examples
c#asp.netgridviewdevexpress

GridView not encoding values


I have a DevExpress grid view that is bound to data, some of the columns have text including apostrophes represented as '

In my gridview however, this text is not converted to ' and instead displays the representation to the user.

Elsewhere on my page, such as text boxes, this is represented appropriately.

How can I force my gridview to encode these characters the same as other controls?


Solution

  • To solve this problem I created a method in my cs which converted the value into a decoded string,

    public string FormatHTML(object myStringObject)
    {
        string myString = Convert.ToString(myStringObject);
    
        return Server.HtmlDecode(myString);
    }
    

    Then using in the DataGrid, I called this method for each column:

    <dx:GridViewDataColumn Visible="true" VisibleIndex="10">
        <DataItemTemplate>    
           <%# FormatHTML(Eval("QuestionText")) %>
        </DataItemTemplate>
     </dx:GridViewDataColumn>