DataTable HTML in Add Rows new object[]

Total Post:29

Points:107
C#  HTML  Gridview 
 1494  View(s)
Ratings:
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.

  1. Post:46

    Points:324
    Re: DataTable HTML in Add Rows new object[]

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

      Modified On Apr-08-2018 11:27:25 PM

Answer