Here I have created sample that full-fill your requirement.
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnDataBound="OnDataBound">
<Columns>
<asp:BoundField DataField="BranchCode" HeaderText="Branch Code" ItemStyle-Width="30" />
<asp:BoundField DataField="BranchName" HeaderText="Branch Name" ItemStyle-Width="150" />
<asp:BoundField DataField="BranchType" HeaderText="Branch Type" ItemStyle-Width="150" />
<asp:BoundField DataField="City" HeaderText="City" ItemStyle-Width="150" />
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:LinkButton ID="lbtnEdit" Text="Edit" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="lbtnDelete" Text="Delete" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Namespace
using System.Data;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[4] { new DataColumn("BranchCode", typeof(int)),
new DataColumn("BranchName", typeof(string)),
new DataColumn("BranchType",typeof(string)),new DataColumn("City",typeof(string)) });
dt.Rows.Add(102, "test for 102", "Men", "Bangalore");
dt.Rows.Add(102, "test for 102", "Ladies", "Bangalore");
dt.Rows.Add(102, "test for 102", "ATM", "Bangalore");
dt.Rows.Add(103, "test for 103", "Men", "Hyderabad");
dt.Rows.Add(103, "test for 103", "Ladies", "Hyderabad");
dt.Rows.Add(104, "test for 104", "ATM", "Chennai");
dt.Rows.Add(104, "test for 104", "Both", "Chennai");
dt.Rows.Add(218, "test for 218", "Men", "Chennai");
dt.Rows.Add(310, "test for 310", "Ladies", "Delhi");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void OnDataBound(object sender, EventArgs e)
{
for (int i = GridView1.Rows.Count - 1; i > 0; i--)
{
GridViewRow row = GridView1.Rows[i];
GridViewRow previousRow = GridView1.Rows[i - 1];
for (int j = 0; j < row.Cells.Count - 2; j++)
{
if (row.Cells[j].Text == previousRow.Cells[j].Text)
{
if (previousRow.Cells[j].RowSpan == 0)
{
if (row.Cells[j].RowSpan == 0)
{
previousRow.Cells[j].RowSpan += 2;
}
else
{
previousRow.Cells[j].RowSpan = row.Cells[j].RowSpan + 1;
}
row.Cells[j].Visible = false;
}
}
}
}
for (int i = GridView1.Rows.Count - 1; i > 0; i--)
{
GridViewRow row = GridView1.Rows[i];
GridViewRow previousRow = GridView1.Rows[i - 1];
for (int j = row.Cells.Count - 2; j < row.Cells.Count; j++)
{
if (row.Cells[0].Text == previousRow.Cells[0].Text)
{
if (previousRow.Cells[j].RowSpan == 0)
{
if (row.Cells[j].RowSpan == 0)
{
previousRow.Cells[j].RowSpan += 2;
}
else
{
previousRow.Cells[j].RowSpan = row.Cells[j].RowSpan + 1;
}
row.Cells[j].Visible = false;
}
}
}
}
}
Screenshot