How to stop a gridview column from automatically encoding html objects

I am new to asp.net and am facing a problem when using gridview.

I have added some entries containing "&" for example, "PR Murphy and Associates". I did not encode my data before inserting it into the database.

When the gridview changes to edit mode, my text looks like this: "PR Murphy and Associates"

I can stop it from encoding information, I mean just save the text as "PR Murphy and Associates" when pasting, and then after / during editing.

Thank you

+3
source share
2 answers

GridView , HTMLEncode False ( True ).

+5

GridView1_RowDataBound

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
           for (int i = 0; i < e.Row.Cells.Count; i++) 
           {
               string encoded = e.Row.Cells[i].Text;
               e.Row.Cells[i].Text = Context.Server.HtmlDecode(encoded);
           }
    }
}
0

Source: https://habr.com/ru/post/1705555/


All Articles