Reputation: 4915
Using aspnet 3.5, c# - Is there a way to insert Html into a gridview row?
Upvotes: 10
Views: 15213
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
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