title: How to merge rows in gridview
body: <p>I have some data in gridview as below.</p>
  
  <p><a href="https://i.stack.imgur.com/Nyp3j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nyp3j.png" alt="enter image description here"></a></p>
  
  <p>I want to merge the rows in gridview as below.</p>
  
  <p><a href="https://i.stack.imgur.com/VImjI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VImjI.png" alt="enter image description here"></a></p>
  
  <p>I already tried with below code in RowDataBound() and PreRender(), the result is not the same as I want.</p>
  
  <pre><code>for (int rowIndex = GridView1.Rows.Count - 2; rowIndex &gt;= 0; rowIndex--)
  {
      GridViewRow gvRow = GridView1.Rows[rowIndex];
      GridViewRow gvPreviousRow = GridView1.Rows[rowIndex + 1];
      for (int cellCount = 0; cellCount &lt; gvRow.Cells.Count; cellCount++)
      {
          if (gvRow.Cells[cellCount].Text ==
                              gvPreviousRow.Cells[cellCount].Text)
          {
              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>In aspx,</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" Width="100%"
      AutoGenerateColumns = "false" AlternatingRowStyle-BackColor = "#fffccc" HeaderStyle-ForeColor ="#ffffff" 
      HeaderStyle-BackColor = "#333" AllowPaging ="true" OnRowDataBound="GridView1_RowDataBound" PageSize = "20"
      OnPageIndexChanging="GridView1_PageIndexChanging" OnPreRender="GridView1_PreRender"&gt;
      &lt;HeaderStyle Height="30px" /&gt;
          &lt;Columns&gt;
              &lt;asp:TemplateField HeaderText="Client Company"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lblClientCompany" runat="server" Text='&lt;%# Eval("ClientCompany")%&gt;'&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Position"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lblPosition" runat="server" Text='&lt;%# Eval("Position")%&gt;'&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Candidate"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lblCandidate" runat="server" Text='&lt;%# Eval("Candidate")%&gt;'&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Status"&gt;
                  &lt;ItemTemplate&gt;
                      asp:Label ID="lblStatus" runat="server" Text='&lt;%# Eval("Status")%&gt;'&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
          &lt;/Columns&gt;
      &lt;AlternatingRowStyle BackColor="#fffccc"  /&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Please help me becasue I have no idea. Thanks.</p>