DATATABLE HTML IN ADD ROWS NEW OBJECT[]

Maria Susan

Total Post:29

Points:107
Posted by  Maria Susan
C#  HTML  Gridview 
 1181  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. sandy taylor

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

        }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!