Hi crajesh,
As per your query i have create the sample.If you have any doubt please revert me back.Below is the given sample.
HTML
<table>
<tr>
<td align="left" valign="top">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="Gridview"
DataKeyNames="Prod_ID" ShowFooter="true" OnDataBound="OnDataBound" CellPadding="4"
AllowPaging="false" AllowSorting="false">
<HeaderStyle BackColor="#9CAAC1" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
<PagerStyle BackColor="#9CAAC1" Font-Bold="True" ForeColor="Black" HorizontalAlign="Center" />
<FooterStyle BackColor="#9CAAC1" Font-Bold="True" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="Black" Font-Names="Verdana" Font-Size="12px" />
<SelectedRowStyle BackColor="lightGray" Font-Bold="false" ForeColor="Black" Font-Names="Verdana"
Font-Size="12px" />
<Columns>
<asp:BoundField DataField="Prod_ID" HeaderText="Prod_ID" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="Right" />
<asp:BoundField DataField="Prod_Name" HeaderText="Prod_Name" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="Cust_Name" HeaderText="Cust_Name" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="Price" HeaderText="Price" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="Right" DataFormatString="{0:c}" />
<asp:TemplateField HeaderText="#" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"
ItemStyle-VerticalAlign="Middle" HeaderStyle-Wrap="true" ItemStyle-Wrap="true">
<ItemTemplate>
<asp:Button ID="lnk_Save1" runat="server" OnClick="lnk_Save_Click" Style="text-align: center;
height: 25px;" ClientIDMode="Static" Text="Save"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
CS
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Fill_GV();
}
}
public void Fill_GV()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[4] {
new DataColumn("Prod_ID"), new DataColumn("Prod_Name"),
new DataColumn("Cust_Name"), new DataColumn("Price") });
dt.Rows.Add(1, "Mobile", "Rajesh", "1000");
dt.Rows.Add(2, "Laptop", "Rajesh", "1000");
dt.Rows.Add(3, "TV", "Rajesh", "1000");
dt.Rows.Add(3, "TV", "Ram", "200");
dt.Rows.Add(3, "TV", "Raj", "1000");
dt.Rows.Add(2, "Laptop", "Seeta", "200");
dt.Rows.Add(3, "TV", "Seeta", "1000");
dt.Rows.Add(2, "Laptop", "Geeta", "1000");
dt = dt.Select("", "Cust_Name asc").CopyToDataTable();
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; j++)
{
if (row.Cells[2].Text.Trim().ToLower() == previousRow.Cells[2].Text.Trim().ToLower())
{
if (previousRow.Cells[4].RowSpan == 0)
{
if (row.Cells[4].RowSpan == 0)
{
previousRow.Cells[4].RowSpan += 2;
}
else
{
previousRow.Cells[4].RowSpan = row.Cells[4].RowSpan + 1;
}
row.Cells[4].Visible = false;
}
}
}
}
}
protected void lnk_Save_Click(object sender, EventArgs e)
{
Button lnk = sender as Button;
GridViewRow GVR = (GridViewRow)lnk.NamingContainer;
GridView1.SelectedIndex = GVR.DataItemIndex;
string Row_Index = GVR.RowIndex.ToString();
string Prod_ID = GridView1.DataKeys[GVR.RowIndex].Values["Prod_ID"].ToString();
}
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
VB
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Fill_GV()
End If
End Sub
Public Sub Fill_GV()
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(3) {New DataColumn("Prod_ID"), New DataColumn("Prod_Name"), New DataColumn("Cust_Name"), New DataColumn("Price")})
dt.Rows.Add(1, "Mobile", "Rajesh", "1000")
dt.Rows.Add(2, "Laptop", "Rajesh", "1000")
dt.Rows.Add(3, "TV", "Rajesh", "1000")
dt.Rows.Add(3, "TV", "Ram", "200")
dt.Rows.Add(3, "TV", "Raj", "1000")
dt.Rows.Add(2, "Laptop", "Seeta", "200")
dt.Rows.Add(3, "TV", "Seeta", "1000")
dt.Rows.Add(2, "Laptop", "Geeta", "1000")
dt = dt.[Select]("", "Cust_Name asc").CopyToDataTable()
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
Protected Sub OnDataBound(sender As Object, e As EventArgs)
For i As Integer = GridView1.Rows.Count - 1 To 1 Step -1
Dim row As GridViewRow = GridView1.Rows(i)
Dim previousRow As GridViewRow = GridView1.Rows(i - 1)
For j As Integer = 0 To row.Cells.Count - 1
If row.Cells(2).Text.Trim().ToLower() = previousRow.Cells(2).Text.Trim().ToLower() Then
If previousRow.Cells(4).RowSpan = 0 Then
If row.Cells(4).RowSpan = 0 Then
previousRow.Cells(4).RowSpan += 2
Else
previousRow.Cells(4).RowSpan = row.Cells(4).RowSpan + 1
End If
row.Cells(4).Visible = False
End If
End If
Next
Next
End Sub
Protected Sub lnk_Save_Click(sender As Object, e As EventArgs)
Dim lnk As Button = TryCast(sender, Button)
Dim GVR As GridViewRow = DirectCast(lnk.NamingContainer, GridViewRow)
GridView1.SelectedIndex = GVR.DataItemIndex
Dim Row_Index As String = GVR.RowIndex.ToString()
Dim Prod_ID As String = GridView1.DataKeys(GVR.RowIndex).Values("Prod_ID").ToString()
End Sub
Public Overrides Sub VerifyRenderingInServerForm(control As Control)
' Verifies that the control is rendered
End Sub
End Class
Screenshot
