0

I have a method to create a DataTable:

private DataTable GetCssPropertiesDataTable()
{
    DataTable dataTable = new DataTable();

    DataColumn column;
    DataRow row;

    column = new DataColumn();
    column.DataType = typeof(string);
    column.ColumnName = "Property";
    column.Caption = "Property";
    dataTable.Columns.Add(column);

    column = new DataColumn();
    column.DataType = typeof(double);
    column.ColumnName = "Value";
    column.Caption = "Value";
    dataTable.Columns.Add(column);

    column = new DataColumn();
    column.DataType = typeof(string);
    column.ColumnName = "Unit";
    column.Caption = "Unit";
    dataTable.Columns.Add(column);

    row = dataTable.NewRow();
    row["Property"] = "A";
    row["Value"] = A;
    row["Unit"] = "m<sup>2</sup>";
    dataTable.Rows.Add(row);

    return dataTable;
}

a gridview (aspx):

<asp:GridView ID="cssPropertiesGridView" runat="server" CssClass="gridView"></asp:GridView>

and databinding in code behing (aspx.cs):

cssPropertiesGridView.DataSource = calculator.CssPropertiesDataTable;
cssPropertiesGridView.DataBind();

the result on a generated web page:

m<sup>2</sup>

Is there way how to display m2 ?

1 Answer 1

3

You should specify the property HtmlEncode="false" for unit column (in datagrid) like in the following snippet, in order to display html

<Columns>
    <asp:BoundField DataField="Property" />
    <asp:BoundField DataField="Value" />
    <asp:BoundField DataField="Unit" HtmlEncode="False" />
</Columns>

Hope it helps.

Sign up to request clarification or add additional context in comments.

2 Comments

how can you do this with the datatable object. something like datatable.columns[1].htmlEncode= false?
Not sure I'm getting your question properly. A datatable is an object used to store some data in memory. A gridview is a control which can render data, so in this particular case a datatable configured as datasource. Now the subject here is how can we handle HTML avoiding the encoding as text? This is something we can do acting on the rendering of the data more than on the data side. Even assuming you changed the encoding in the datatable (or even in your source, database, file, service...), that wouldn't prevent the gridview from encoding once the databind is performed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.