DataTable HTML in Add Rows new object[]

I created a DataTable and I am adding new rows with new object[].

DataTable dt = new DataTable();


dt.Rows.Add(new object[] { "Hello", "World", "<i>Test</i>" });

In the object[] array I got some values that are shown in the DataTable.

I would like to add some HTML styling, is this possible like above? I would like to have the Testshown as italic.

Thanks in advance.

Last updated:1/18/2015 10:36:16 PM

1 Answers

Anonymous User
Anonymous User

The DataTable stores data, it it not responsible for any format or styling. So it depends on where you want to diplay it, if it's an ASP.NET-GridView you could use the RowDataBound event. HttpUtility.HtmlDecode should work to prevent that your html will be encoded:

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