Prevent HTML encoding in auto-generated GridView columns

前端 未结 7 2118
渐次进展
渐次进展 2020-11-27 06:46

I have a GridView bound to a DataTable that I construct. Most columns in the table contain the raw HTML for a hypelinklink, and I would like that HTML to render as a link i

7条回答
  •  一生所求
    2020-11-27 07:31

    You can use this code in RowDataBound event if you want to disable HTML encoding in all rows and columns.

    protected void GV_Product_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            foreach (TableCell ObjTC in e.Row.Cells)
            {
                string decodedText = HttpUtility.HtmlDecode(ObjTC.Text);
                ObjTC.Text = decodedText;
            }
        }
    }
    

提交回复
热议问题