I have searched about this a lot in google. But, i didn't get any clue. Thanks to you all in advance.
Question: i have a html source in my datatable column.when it binds with my gridview, i need to show that html output in my gridview column. Is that Possible ?
current output:
My aspx code:
protected void Page_Load(object sender, EventArgs e)
{
DataTable dtEmployees = new DataTable();
dtEmployees.Columns.Add(new DataColumn("FirstName", typeof(System.String)));
dtEmployees.Columns.Add(new DataColumn("LastName", typeof(System.String)));
dtEmployees.Columns.Add(new DataColumn("HomePhone", typeof(System.String)));
dtEmployees.Columns.Add(new DataColumn("CellPhone", typeof(System.String)));
dtEmployees.Columns.Add(new DataColumn("Address", typeof(System.String)));
DataRow drEmpDetail = dtEmployees.NewRow();
drEmpDetail["FirstName"] = "Tony";
drEmpDetail["LastName"] = "Greg";
drEmpDetail["HomePhone"] = "000-000-0000";
drEmpDetail["CellPhone"] = "000-000-0000";
drEmpDetail["Address"] = "Lane 1 Suite # 2 <br>";
}
Just for example,In the Address column i have given html tag for the "break tag".But in the output it just displays like a string, the result is not as expected.
Note: I don't want to use the Template field instead of BoundField.
Try using - HttpUtility.HtmlDecode("Lane 1 Suite # 2 <br>")
The markup will be,
<asp:TemplateField HeaderText="Address">
<ItemTemplate>
<%# HttpUtility.HtmlDecode(Eval("Address").ToString()) %>
</ItemTemplate>
</asp:TemplateField>
Ref : http://msdn.microsoft.com/en-us/library/7c5fyk1k.aspx
Set HtmlEncode
to false in your bounfield property
<asp:BoundField HeaderText="Address" DataField="YourDataField" HtmlEncode="false" />
BoundField HTML Encode Property MSDN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With