Home > DeveloperSection > Forums > DataTable HTML in Add Rows new object[]
Maria Susan

Total Post:29

Posted on    January-18-2015 10:15 PM

 ASP.Net C#  HTML  Gridview 

 1 Reply(s)
 1093  View(s)
Rate this:

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.

sandy taylor
sandy taylor

Total Post:46

Posted on    January-18-2015 10:36 PM

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);



Don't want to miss updates? Please click the below button!

Follow MindStick