Sometimes we need
to include HTML formatted data within some fields of SPGridView. I have worked
on one requirement in which I have to include multiple Hyperlinks into one
field of HTML in which I have written like “<a>” , and when SPGridView
renders it shows entire HTML Code, not hyperlinks.
An easy way
around this is to set the HTMLEncode property to false. By
default this property is set to true, which will encode your HTML so that it will
show up as code, changing <’s and >’s into < and >, and so
on.
Sample Code:
#region Create Child Controls
protected override void
CreateChildControls()
{
try
{
grdData = new SPGridView();
grdData.AutoGenerateColumns = false;
BoundField colTitle = new BoundField();
colTitle.HeaderText = "Title";
colTitle.HtmlEncode = false;
//This is the line
colTitle.DataField = "Title";
this.grdData.Columns.Add(colTitle);
…
this.Controls.Add(this.grdData);
}
catch (Exception ex)
{
}
}
#endregion
Enjoy!!!