【发布时间】:2013-12-07 13:55:40
【问题描述】:
我有一个数据集,其中每行有 3 列标题、链接和描述。这必须绑定到 Gridview。 当绑定到 Gridview 时,结果显示为 标题链接描述(即在一行中,所有三个值都显示为一个数据集行)
我需要结果显示在
Title
Link
Description
也就是说,我需要按行显示结果。
谁能告诉我如何实现它。
【问题讨论】:
我有一个数据集,其中每行有 3 列标题、链接和描述。这必须绑定到 Gridview。 当绑定到 Gridview 时,结果显示为 标题链接描述(即在一行中,所有三个值都显示为一个数据集行)
我需要结果显示在
Title
Link
Description
也就是说,我需要按行显示结果。
谁能告诉我如何实现它。
【问题讨论】:
您可以使用模板字段来做到这一点。
<asp:GridView ID="GridView1" runat="server" ShowHeader="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table>
<tr>
<td>
Title
</td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("title") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
Link
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("link") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
Decsription
</td>
<td>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("description") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
【讨论】: