How to stop gridview column from automatically encoding html entities

放肆的年华 提交于 2019-12-13 14:04:03

问题


I am fairly new to asp.net and come into a problem whilst using a gridview.

I have added some entries that contain the "&" symbol eg "PR Murphy & Associates". I haven't done any encoding of my data prior to inserting it into the database.

When the gridview is changed to edit mode my text looks like this: "PR Murphy & Associates"

Is thee a ny way I can stop it from encoding the information, I mean just keep the text as "PR Murphy & Associates" when inserting and then after/during an edit.

Thanking you


回答1:


In the GridView's menu, you can select the column and under the properties for that column you can set HTMLEncode to False (or True depending upon your needs).




回答2:


I solved this problem with GridView1_RowDataBound Event

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);
           }
    }
}


来源:https://stackoverflow.com/questions/696455/how-to-stop-gridview-column-from-automatically-encoding-html-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!