如何在 gridview 的每一行之后重复标题行?
您可以将代码添加到网格的 rowdatabound-event 中:
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow row = new GridViewRow(e.Row.RowIndex, 0, DataControlRowType.Header, DataControlRowState.Normal);
TableCell cell = new TableCell();
cell.Controls.Add(new Label { Text = "Header" }); //as needed
row.Cells.Add(cell);
Table tbl = (e.Row.Parent as Table);
tbl.Controls.AddAt(e.Row.RowIndex * 2 + 1, row);
}
}
在此示例中,我已完全删除了 gridview 标头,因为您可以在后面的代码中编写自己的标头。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)