有没有办法让DataGrid控件呈现tbody和thead HTML元素?
虽然我喜欢"user186197"的答案,但该博客文章使用反射,但在非完全信任的托管环境中可能会出错.这是我们使用的,没有黑客:
public class THeadDataGrid : System.Web.UI.WebControls.DataGrid
{
protected override void OnPreRender(EventArgs e)
{
this.UseAccessibleHeader = true; //to make sure we render TH, not TD
Table table = Controls[0] as Table;
if (table != null && table.Rows.Count > 0)
{
table.Rows[0].TableSection = TableRowSection.TableHeader;
table.Rows[table.Rows.Count - 1].TableSection = TableRowSection.TableFooter;
}
base.OnPreRender(e);
}
}
Run Code Online (Sandbox Code Playgroud)
DataGrid 没有内置的东西来满足您的需求。看一下ASP.NET 2.0 CSS 友好控制适配器 1.0,它们内置了对 DataView 的支持,但似乎您可以轻松地将这种想法应用于 DataGrid。
| 归档时间: |
|
| 查看次数: |
8500 次 |
| 最近记录: |