我想使用C#+ ASP.net显示网格视图的Merge标题,如下图所示:
知道如何实现这个目标吗?
答案 0 :(得分:2)
您可以使用网格视图的Row_Created事件。您可以在其中设置网格视图的ColSpan和行跨度属性
请参阅以下示例代码:
protected void grvMergeHeader_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView HeaderGrid = (GridView)sender;
GridViewRow HeaderGridRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell HeaderCell = new TableCell();
HeaderCell.Text = "Employee Information";
HeaderCell.ColumnSpan = 3;
HeaderGridRow.Cells.Add(HeaderCell);
HeaderCell = new TableCell();
HeaderCell.Text = "Joining Date";
HeaderCell.ColumnSpan = 2;
HeaderGridRow.Cells.Add(HeaderCell);
grvMergeHeader.Controls[0].Controls.AddAt(0, HeaderGridRow);
}
}
有关详情,请参阅以下链接merging grid view header here