I have two gridview's in my page (gridview inside a gridview) in the main gridview i want to merge all the duplicate values of first cells. i am binding both the gridview at runtime. please help
aspx:
<asp:GridView ID="MainGridview" runat="server" AutoGenerateColumns="true" ShowFooter="True"
SkinID="gridviewMAST" EmptyDataText="No Records Found." RowStyle-Wrap="true"
AlternatingRowStyle-Wrap="true" CellPadding="6" OnRowDataBound="MainGridview_RowDataBound"
OnRowCreated="MainGridview_RowCreated">
<Columns>
<asp:TemplateField HeaderText="Action Item" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="false">
<ItemTemplate>
<asp:GridView ID="grdItemNested" runat="server" AllowPaging="true">
<Columns>
</Columns>
<HeaderStyle BackColor="#5D7B9D" ForeColor="White" Height="30px" Font-Bold="true" />
<RowStyle Height="20px" BackColor="#FFFFFF" ForeColor="#000000" />
<AlternatingRowStyle BackColor="#D3D3D3" ForeColor="#000000" />
<FooterStyle BackColor="#5D7B9D" ForeColor="White" Height="30px" Font-Bold="true" />
</asp:GridView>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
</asp:TemplateField>
</Columns>
<EmptyDataRowStyle Height="25px" Font-Bold="true" />
<RowStyle Height="20px" />
<PagerStyle Height="30px" />
<HeaderStyle Height="30px" Font-Bold="true" />
<FooterStyle Height="30px" Font-Bold="true" />
</asp:GridView>
am using a OnDataBound event to achieve this but when am running the application only first record is merge in the gridview and alignment is not proper of the main gridview. can please someone help me as to rectify what am missing here.
.cs
protected void MainGridview_DataBound1(object sender, EventArgs e)
{
for (int rowIndex = MainGridview.Rows.Count - 2;
rowIndex >= 0; rowIndex--)
{
GridViewRow gvRow = MainGridview.Rows[rowIndex];
GridViewRow gvPreviousRow = MainGridview.Rows[rowIndex + 1];
for (int cellCount = 0; cellCount < gvRow.Cells.Count;
cellCount++)
{
if (gvRow.Cells[cellCount].Text ==
gvPreviousRow.Cells[cellCount].Text)
{
if (gvPreviousRow.Cells[cellCount].RowSpan < 2)
{
gvRow.Cells[cellCount].RowSpan = 2;
}
else
{
gvRow.Cells[cellCount].RowSpan =
gvPreviousRow.Cells[cellCount].RowSpan + 1;
}
gvPreviousRow.Cells[cellCount].Visible = false;
}
}
}
}