有没有办法将Html插入到gridview行?
问题描述:
使用aspnet 3.5,c# - 有没有办法将Html插入gridview行?
Using aspnet 3.5, c# - Is there a way to insert Html into a gridview row?
答
是的。使用 TemplateField
,然后直接在标记中输入你的html。如果html假设是动态创建的,我会使用 Literal
而不是 Label
。
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>