6

我有一个看起来像这样的对象:

public class TestData
{
    public string FirstName {get; set;}
    public string LastName {get; set;}
    public string Email {get; set;}
    public string Phone {get; set;}
}

我有 10 个该类的实例存储在IENumerable.

GridView我的文件中也有一个aspx

<asp:GridView ID="GridView1" runat="server">
</asp:GridView>

我需要的是一种IENumerableGridView. 但我希望能够thead自己在表格中设置“标题”。

所以我得到这样的东西:

<table>
  <thead>
    <th>Firstname</th>
    <th>Firstname</th>
    <th>Telephone</th>
    <th>Email address</th>
  </thead>
  <tbody>
    <!-- the values from each TestData class stored in the IENumberable -->
  </tbody>
</table>

我可以使用 a 来执行此操作,GridView还是使用其他控件更好地完成这项工作?我还记得一些关于模板的事情?不确定,我对 ASP.NET 很陌生。

4

1 回答 1

5

您可以将绑定字段与明确HeaderText的绑定字段一起使用。
使用自动生成列为假。

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumn="false">
    <asp:BoundField DataField="FirstName" HeaderText="First Name" />
    <asp:BoundField DataField="LastName " HeaderText="Last Name" />
    .....
</asp:GridView>

编辑 1

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumn="false">
  <Columns>
    <asp:BoundField DataField="FirstName" HeaderText="First Name" />
    <asp:BoundField DataField="LastName " HeaderText="Last Name" />
    .....
  </Columns>
</asp:GridView>

于 2013-02-21T08:16:39.227 回答