Give the below query in aspx page
Now run Your Program Your OutPut Looks Like Given Below
<asp:GridView
ID="gvwRaja"
runat="server"
onprerender="gvwRaja_PreRender" onrowdatabound="gvwRaja_RowDataBound"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
CellPadding="3" CellSpacing="2">
<FooterStyle BackColor="#F7DFB5"
ForeColor="#8C4510"
/>
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
Then give the below queryin aspx.cs page
protected void
Page_Load(object sender, EventArgs e)
{
if
(!IsPostBack)
CreateTable();
}
private void CreateTable()
{
DataTable dt = new
DataTable();
dt.Columns.Add("CountryId");
dt.Columns.Add("CountryName");
dt.Columns.Add("State");
dt.Rows.Add("1",
"India", "TamilNadu");
dt.Rows.Add("1",
"India",
"Delhi");
dt.Rows.Add("1",
"India", "Andhra Pradesh");
dt.Rows.Add("1",
"India",
"Maharashtra");
dt.Rows.Add("2",
"US",
"Alabama");
dt.Rows.Add("2",
"US",
"Hawaii");
dt.Rows.Add("3",
"UK",
"United Kingdom");
gvwRaja.DataSource = dt;
gvwRaja.DataBind();
}
protected void gvwRaja_PreRender(object
sender, EventArgs e)
{
Class2.MergeRows(gvwRaja);
}
Then create a class file nane same as (Class2)
Then give the query in class2 page
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 cellIndex = 0; cellIndex <
row.Cells.Count; cellIndex++)
{
if
(row.Cells[cellIndex].Text == previousRow.Cells[cellIndex].Text)
{
row.Cells[cellIndex].RowSpan = previousRow.Cells[cellIndex].RowSpan <
2 ? 2 : previousRow.Cells[cellIndex].RowSpan + 1;
previousRow.Cells[cellIndex].Visible = false;
}
}
}
}
Now run Your Program Your OutPut Looks Like Given Below