效果图如下: 方法一 GridView 的 RowDataBound 事件: #region RowDataBound 事件 int row = 0; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { int rowindex = e.Row.RowIndex; if (rowindex - 1 < 0) return; if (e.Row.Cells[0].Text == GridView1.Rows[rowindex - 1].Cells[0].Text) { if (GridView1.Rows[row].Cells[0].RowSpan == 0) GridView1.Rows[row].Cells[0].RowSpan++; GridView1.Rows[row].Cells[0].RowSpan++; e.Row.Cells[0].Visible = false; } else { row = rowindex; } } #endregion 方法二 GridView的 DataBound 事件: #region DataBound 事件 protected void GridView1_DataBound(object sender, EventArgs e) { int row = 0; for (int i = 1; i < GridView1.Rows.Count; i++) { if (GridView1.Rows[i].Cells[0].Text == GridView1.Rows[i - 1].Cells[0].Text) //if (Convert.ToInt64(GridView1.DataKeys[GridView1.Rows[i].RowIndex].Value) == Convert.ToInt64(GridView1.DataKeys[GridView1.Rows[i-1].RowIndex].Value)) { if (GridView1.Rows[row].Cells[1].RowSpan == 0) { GridView1.Rows[row].Cells[0].RowSpan++; } GridView1.Rows[row].Cells[0].RowSpan++; GridView1.Rows[i].Cells[0].Visible = false; } else { row = i; } } } #endregion 方法三 GridView 的 OnPreRender事件: #region OnPreRender事件 public void GridView1_PreRender(object sender, System.EventArgs e) { if (this.GridView1.Rows.Count <1) { return; } int col = 0; int k = GridView1.Rows.Count; TableCell oldtc = this.GridView1.Rows[0].Cells[col]; for (int i = 1; i < k; i++) { TableCell tc = this.GridView1.Rows[i].Cells[col]; if (tc.Text == oldtc.Text) { tc.Visible = false; if (oldtc.RowSpan == 0) { oldtc.RowSpan = 1; } oldtc.RowSpan = oldtc.RowSpan + 1; oldtc.VerticalAlign = VerticalAlign.Middle; } else { oldtc = tc; } } } #endregion