Victor Franchi
Victor Franchi

Reputation: 163

Putting HTML inside dynamically made column on aspx GridView

i'm trying to put a html div that contains an style that represents a dot (green, yellow or red). The thing is: I have to put this html inside a gridview (histRagStatus) column that was programatically made, as you can see:

    private void popularHistoricoRAGStatus()
    {
             DataTable ragTable =ProjetoBO.HistoricoRAGStatusProjeto(Convert.ToInt32(Session["idProjeto"]));

        int agrupadorRagStatus = -1;

        int cont = 1;

        var tabelaFinal = PegarDataTable();

        DataRow dataRow = tabelaFinal.NewRow();

        foreach (DataRow row in ragTable.Rows)
        {
            cont++;
            if (Convert.ToInt32(row[9]) != agrupadorRagStatus)
            {
                cont = 1;
                agrupadorRagStatus = Convert.ToInt32(row[9]);
                tabelaFinal.Rows.Add(dataRow);
                dataRow = tabelaFinal.NewRow();
                dataRow[1] = PegarCorIndicadorRagStatus(Convert.ToInt32(row[3]),row[6].ToString());
                continue;
            }
            dataRow[0] = DateTime.Parse(row[2].ToString()).ToShortDateString();

            dataRow[cont] = PegarCorIndicadorRagStatus(Convert.ToInt32(row[3]), row[6].ToString());

        }

        histRagStatus.DataSource = tabelaFinal;
        histRagStatus.DataBind();
   }

I got this DataTable that I fill with data from the database and I put it as a data source to the grid view. But Here is the problem: when I have a table with static column, that I put while on design, it works OK, the html is converted into the images, but when I put the SAME HTML into a programatically made column, it doesn't work, it becomes the HTML text itself as you can see here https://www.dropbox.com/s/rf07ecu66axmzg0/Sem%20t%C3%ADtulo.png

I'm stuck with this, any help would be appreciated

Upvotes: 0

Views: 2134

Answers (1)

AntLaC
AntLaC

Reputation: 1225

Within your new column assign HtmlEncode="False"

<asp:GridView ID="GridView1" runat="server">
            <Columns>
                <asp:DynamicField HtmlEncode="False"></asp:DynamicField>
            </Columns>
        </asp:GridView>

Upvotes: 1

Related Questions