//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為當前日期 //重新統(tǒng)計跨行 publishDateCell = e.Row.Cells[2]; publishDateCell.RowSpan = 1; } } } } |