Asp.net 用IENumerable对象填充GridView

Asp.net 用IENumerable对象填充GridView,asp.net,webforms,Asp.net,Webforms,我有一个像这样的对象: public class TestData { public string FirstName {get; set;} public string LastName {get; set;} public string Email {get; set;} public string Phone {get; set;} } <table> <thead> <th>Firstname</th

我有一个像这样的对象:

public class TestData
{
    public string FirstName {get; set;}
    public string LastName {get; set;}
    public string Email {get; set;}
    public string Phone {get; set;}
}
<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>
我在
IENumerable
中存储了该类的10个实例

我的
aspx
文件中还有一个
GridView

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

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

您可以将绑定字段与绑定字段的显式
标题文本一起使用。
使用“自动生成列”设置为false

<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

.....

谢谢,我理解
边界字段
,但我仍然不确定如何将我的
IENumerable
绑定到gridview。我所能找到的只是关于如何将其连接到数据库的信息。知道如何将我的
IENumerable
绑定到它吗?我还遇到了一个错误:GridView没有名为“BoundField”的公共属性@Vivendi很抱歉,它应该在列标记内。我已经编辑了我的答案。谢谢,现在可以了。关于“将对象绑定到网格”,我是这样做的(对于其他需要它的人):我创建了一个
列表
,其中包含我的
TestData
类的一个实例。我将列表添加到GridView中,如下所示:
GridView1.DataSource=myList;GridView1.DataBind()---现在一切正常:)
<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>