I suggest you to perform this in gridview as follows:
<asp:GridView ID="GridView6" runat="server" AutoGenerateColumns="false"
OnPreRender="GridView6_PreRender" >
<Columns>
<asp:BoundField DataField="one" HeaderText="" SortExpression="code" />
<asp:BoundField DataField="two" HeaderText="" SortExpression="name" />
<asp:BoundField DataField="three" HeaderText="" SortExpression="date1"
/>
<asp:BoundField DataField="four" HeaderText="" SortExpression="leave" />
<asp:BoundField DataField="five" HeaderText="" SortExpression="ltype" />
</Columns>
</asp:GridView>
On prerender event call the MergeRows function:
protected void GridView6_PreRender(object sender, EventArgs e)
{
MergeRows(GridView6);
}
And below is the function:
public static void MergeRows(GridView gridView)
{
for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow row = gridView.Rows[rowIndex];
GridViewRow previousRow = gridView.Rows[rowIndex + 1];
for (int i = 0; i < row.Cells.Count - 2; i++)
{
if (row.Cells[i].Text == previousRow.Cells[i].Text)
{
row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 :
previousRow.Cells[i].RowSpan + 1;
previousRow.Cells[i].Visible = false;
}
}
}
}
Hope this helps.!