GridView合并单元格 //GridView合并单元格 //中间变量,存取TableCell private TableCell publishDateCell = null; protected void grvTest_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //第一行,publishDateCell=null if (publishDateCell == null) { publishDateCell = e.Row.Cells[2]; publishDateCell.RowSpan = 1; } else { //判断当前行的日期是否和publishDateCell一致 //如果一致,跨行 if (e.Row.Cells[2].Text == publishDateCell.Text) { e.Row.Cells[2].Visible = false; publishDateCell.RowSpan++; } else { //如果不等,更新publishDateCell为当前日期 //重新统计跨行 publishDateCell = e.Row.Cells[2]; publishDateCell.RowSpan = 1; } } }