Have you seen this article "Merge Two GridView Header columns in ASP.NET"? It builds the header row as you see fit. When you do this, you'll have to explicitly build each header (i.e. if you're merging Customer First Name and Customer Last Name, you'll have to ensure you explicitly include Customer ID and Customer Address, etc. as required.)
protected void myGridView_ItemCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
//custom header.
GridView gvHeader = (GridView)sender;
GridViewRow gvHeaderRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell tc1 = new TableCell();
// First column
tc1.Text = "Merged Column1";
tc1.ColumnSpan = 2;
tc1.BackColor = System.Drawing.Color.Brown;
gvHeaderRow.Cells.Add(tc1);
// Second column
tc1 = new TableCell();
tc1.Text = "Merged Column2";
tc1.ColumnSpan = 2;
gvHeaderRow.Cells.Add(tc1);
//keep building as needed.
gvHeader.Controls[0].Controls.AddAt(0, gvHeaderRow);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…