Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 329
Lill Lansey Avatar asked Oct 05 '09 19:10

Lill Lansey


2 Answers

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>
like image 164
Chris Avatar answered Oct 24 '22 09:10

Chris


Simply modify the Text property of a cell.

like image 20
Steven Avatar answered Oct 24 '22 11:10

Steven