我有一个看起来像这样的对象:
public class TestData
{
public string FirstName {get; set;}
public string LastName {get; set;}
public string Email {get; set;}
public string Phone {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我有10个该类的实例存储在一个IENumerable.
GridView我的aspx文件中也有一个:
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
Run Code Online (Sandbox Code Playgroud)
我需要的是一种显示内容IENumerable的方法GridView.但我希望能够自己设置表中的"标题" 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>
Run Code Online (Sandbox Code Playgroud)
我可以使用GridView或者更好地使用其他控件来完成工作吗?我还记得一些关于模板的事吗?不确定,我是ASP.NET的新手.
您可以使用明确HeaderText绑定字段的绑定字段.
使用自动生成列为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>
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2949 次 |
| 最近记录: |