Hazel Mahmud

Hazel Mahmud

  • NA
  • 299
  • 65.3k

merge gridview row with data

Jul 7 2021 3:52 PM

i have code as below..how to fix it so that the last column did not appear. Please help.

ASPX

 <asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="250px">
                    <HeaderTemplate>
                       <asp:Label ID="lbllocation" Text="Department" runat="server" />
                        <asp:DropDownList ID="ddllocation" runat="server" AutoPostBack="true" Width="120px" CssClass="ddlstyle"
                          OnSelectedIndexChanged="ddllocation_SelectedIndexChanged">                 
                        </asp:DropDownList>
                    </HeaderTemplate>
                    <ItemTemplate>
                          <%# Eval("PTJDesc") %>                   
                    </ItemTemplate>
                </asp:TemplateField>

if i use below code, the output is the follows image

aspx.cs

   protected void gvAuditPlanSearch_RowDataBound(object sender, GridViewRowEventArgs e)
        {        

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowIndex > 0)
                {
                    GridViewRow previousRow = gvAuditPlanSearch.Rows[e.Row.RowIndex - 1];
                    if (e.Row.Cells[9].Text == previousRow.Cells[9].Text)
                    {
                        if (previousRow.Cells[9].RowSpan == 0)
                        {
                            previousRow.Cells[9].RowSpan += 2;

                           //e.Row.Cells[9].Visible = false; <--
                        }
                    }
                }
            }
        }

 

but if i use this code, the data after the first row of column department did not appear...

protected void gvAuditPlanSearch_RowDataBound(object sender, GridViewRowEventArgs e)
        {        

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowIndex > 0)
                {
                    GridViewRow previousRow = gvAuditPlanSearch.Rows[e.Row.RowIndex - 1];
                    if (e.Row.Cells[9].Text == previousRow.Cells[9].Text)
                    {
                        if (previousRow.Cells[9].RowSpan == 0)
                        {
                            previousRow.Cells[9].RowSpan += 2;

                          e.Row.Cells[9].Visible = false; <--
                        }
                    }
                }
            }
        }

 


Answers (2)