Lill Lansey
Lill Lansey

Reputation: 4915

Is there a way to insert Html into a gridview row?

Using aspnet 3.5, c# - Is there a way to insert Html into a gridview row?

Upvotes: 10

Views: 15213

Answers (3)

Chris
Chris

Reputation: 2045

Yes. Use the TemplateField, and then type your html directly into the markup. If the html is suppose to be dynamically created I would use a Literal instead of a Label.

<asp:GridView id="GridView1" runat="server">
    <Columns>
        <asp:TemplateField headertext="Column1">
            <ItemTemplate>
                <br />
                <h1>
                    <%# Eval ("DataColumnName") %>
                </h1>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField headertext="Column2">
            <ItemTemplate>
                <asp:Literal id="Literal1" runat="server" text='<%# Eval ("DataColumnName2") %>'></asp:Literal>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Upvotes: 13

Ryan Alford
Ryan Alford

Reputation: 7594

I haven't tested this, but you should be able to add a Label control to the GridView cell. Then write your HTML to the Label's Text property. The Label should render the HTML.

Upvotes: 1

Steven
Steven

Reputation: 13769

Simply modify the Text property of a cell.

Upvotes: 3

Related Questions