问题
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