title: Merge two rows in gridview
body: <p>Here's the code I am using:</p>
  
  <pre><code>protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
  {
      for (int rowIndex = gridView.Rows.Count - 2;
                                    rowIndex &gt;= 0; rowIndex--)
      {
          GridViewRow gvRow = gridView.Rows[rowIndex];
          GridViewRow gvPreviousRow = gridView.Rows[rowIndex + 1];
          for (int cellCount = 0; cellCount &lt; 2; cellCount++)
          {
              if (gvRow.Cells[cellCount].Text.ToUpper().Trim() ==
                                     gvPreviousRow.Cells[cellCount].Text.ToUpper().Trim())
              {
                  if (gvPreviousRow.Cells[cellCount].RowSpan &lt; 2)
                  {
                      gvRow.Cells[cellCount].RowSpan = 2;
                  }
                  else
                  {
                      gvRow.Cells[cellCount].RowSpan =
                          gvPreviousRow.Cells[cellCount].RowSpan + 1;
                  }
                  gvPreviousRow.Cells[cellCount].Visible = false;
              }
          }
      }
  }
  </code></pre>
  
  <p>Output of this code looks like <a href="https://i.stack.imgur.com/O9ZRF.png" rel="nofollow noreferrer">this image</a>.
  Here, red Circle indicates the problem in output. I don't want row merge when the cells to the left columns are different. For example, controlling office should not merge if bank is different.</p>