Hi nauna,
I have created sample that full fill your requirement.
HTML
<div>
<asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="type" HeaderText="type" />
<asp:BoundField DataField="ingredients" HeaderText="ingredients" />
<asp:BoundField DataField="noofingredients" HeaderText="no of ingredients" />
</Columns>
</asp:GridView>
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3]
{
new DataColumn("type", typeof(string)),
new DataColumn("ingredients", typeof(string)),
new DataColumn("noofingredients", typeof(int))
});
dt.Rows.Add("A", "abc", 2);
dt.Rows.Add("B", "cde", 2);
dt.Rows.Add("C", "xyz", 3);
dt.Rows.Add("C", "afg", 3);
dt.Rows.Add("C", "zbc", 3);
DataView dv = dt.DefaultView;
dv.Sort = "noofingredients asc,type asc";
DataTable sortedDT = dv.ToTable();
GridView1.DataSource = sortedDT;
GridView1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int RowSpan = 2;
for (int i = GridView1.Rows.Count - 2; i >= 0; i--)
{
GridViewRow currRow = GridView1.Rows[i];
GridViewRow prevRow = GridView1.Rows[i + 1];
if (currRow.Cells[2].Text == prevRow.Cells[2].Text)
{
currRow.Cells[0].RowSpan = RowSpan;
prevRow.Cells[0].Visible = false;
RowSpan += 1;
}
else
{
RowSpan = 2;
}
}
}
Screenshot