Dipali Patil

Dipali Patil

  • NA
  • 72
  • 79.2k

Merge Gride view Repited columns

Jul 22 2010 8:12 AM
Hi,

i am tried to merge to grid view repited record like..

1>> Source Code
 <asp:GridView ID="gvAddBudgetExpenceYear" runat="server" AutoGenerateColumns="False"
                        OnRowDataBound="gvAddBudgetExpenceYear_RowDataBound" >
                        <Columns>
                            <asp:TemplateField HeaderText="BudgetHead">
                                <ItemTemplate>
                                    <asp:Label ID="lblHeadID" runat="server" Text='<%#(Eval("BudgetHeadID").ToString())%>' Visible="false"></asp:Label>
                                   <asp:Label ID="lblBudgetHead" runat="server" Text='<%#getBudgetHeadname(Eval("BudgetHeadID").ToString())%>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Budget sub Head">
                                <ItemTemplate>
                                    <asp:Label ID="lblSubHeadID" runat="server" Text='<%#(Eval("BudgetSubHeadID"))%>' Visible="false"></asp:Label>
                                    <asp:Label ID="lblSubHeads" runat="server" Text='<%#(Eval("BudgetSubHeadsParticular"))%>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Budget">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtYearBudget" runat="server" Text=''></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Expence">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtYearExpence" runat="server"></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

-----------------------------------------------
Code behind code >>
 protected void gvAddBudgetExpence_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            for (int rowIndex = gvAddBudgetExpence.Rows.Count - 5;
                                     rowIndex >= 0; rowIndex--)
            {
                GridViewRow gvRow = gvAddBudgetExpence.Rows[rowIndex];
                GridViewRow gvPreviousRow = gvAddBudgetExpence.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;
                    }
                }
            }
}
--------------------
But it is not work properly.

Please help .