GridView vs DataGrid

dotNet 2.0后,M$推荐使用GridView取代DataGrid(Comparing the GridView and DataGrid Web Server Controls)。在做Testlink测试Case的Chart,然后想在表中插入HTML format的时候出现了奇怪的问题。DataGrid一切正常,GridView貌似对直接插入的HTML进行了encode,HTML原始显示了出来。

狂搜一遍,

protected void gvTP_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Text = Server.HtmlDecode(e.Row.Cells[1].Text);
}
}

这下加入的HTML format就不会给encode咯。

Leave a Reply

Your email address will not be published. Required fields are marked *