GridView 如何生成 thead?

作者:vkvi 来源:ITPOW(原创) 日期:2010-11-16

GridView 生成的是表格,它将 header 也等同一般的记录一样生成到 tbody 的 tr 下,但我们其实更希望 header 是生成到 thead 下,怎么办呢?

这种情况下,GridView 会在 table 下生成 thead 和 tbody,thead 用来装 header。

当然,这还不够的,为什么呢?尝尝无记录时的情况,会报错,因为无记录时,没有 HeaderRow。

如果是动态绑定数据,可以将上述代码放在 DataBound 事件中,注意是 DataBound,而不是 RowDataBound。

相关文章