问候!
我仍在学习 GridView 控件,并且我有一个绑定到 ObjectDataSource。我的 Web 表单如下所示:
<asp:GridView ID="ourGrid" runat="server" DataSourceID="ourDataSource" onrowdatabound="ourGrid_RowDataBound"
HeaderStyle-CssClass="header_style" AlternatingRowStyle-CssClass="altrow_style"
ShowFooter="true">
<columns>
<asp:BoundField DataField="Name" HeaderText="Full Name" />
<asp:BoundField DataField="Gender" HeaderText="Gender" />
<asp:BoundField DataField="BirthYear" HeaderText="Year of Birth" />
<asp:BoundField DataField="JoinDate" HeaderText="Date Joined" HtmlEncode="false" DataFormatString="{0:d}" />
</columns>
</asp:GridView>
<asp:ObjectDataSource ID="ourDataSource" runat="server" SelectMethod="GetTopUsers" TypeName="Acme.Model.OurNewObject">
</asp:ObjectDataSource>
它当前生成以下标记:
<table cellpadding="0" cellspacing="0" summary="">
<thead>
<tr style="header_style">
<th scope="col">Full Name</th>
<th scope="col">Gender</th>
<th scope="col">Year of Birth</th>
<th scope="col">Date Joined</th>
</tr>
</thead>
<tfoot>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tfoot>
<tbody>
<tr>
<td>John Smith</td>
<td>Male</td>
<td>1967</td>
<td>17-6-2007</td>
</tr>
<tr class="AspNet-GridView-Alternate altrow_style">
<td>Mary Kay</td>
<td>Female</td>
<td>1972</td>
<td>15-11-2007</td>
</tr>
<tr>
<td>Bill Jones</td>
<td>Male</td>
<td>1970</td>
<td>23-2-2007</td>
</tr>
</tbody>
</table>
还有一些 HTML 元素我想添加到这个 GridView 控件将生成的表格标记中。对于初学者,我需要 TFOOT 看起来像这样:
<tfoot>
<tr>
<td colspan="4">
<div>
<a class="footerlink_style" title="Newest Members" href="#">Newest Members</a>
<a class="footerlink_style" title="Top Posters" href="#">Top Posters</a>
</div>
</td>
</tr>
</tfoot>
链接将不包含数据绑定信息,但可能是超链接控件。有没有办法可以在设计时指定它?
此外,对于 THEAD,是否可以在 GridView 中为每个列标题指定单独的样式?
<thead>
<tr style="header_style">
<th scope="col" style="col1_style">Full Name</th>
<th scope="col" style="col2_style">Gender</th>
<th scope="col" style="col3_style">Year of Birth</th>
<th scope="col" style="col4_style">Date Joined</th>
</tr>
</thead>
最后,是否可以像这样指定表格的摘要属性?
<table cellpadding="0" cellspacing="0" summary="Here is a list of users">
提前致谢。