gridview's last 2 columns shift right after merged cells

doramail05
doramail05 used Ask the Experts™
on
after merching cells like below:

e.Row.Cells.RemoveAt(2);
e.Row.Cells.RemoveAt(3);
e.Row.Cells.RemoveAt(4);
e.Row.Cells[1].ColumnSpan = 4;

notice that the 2nd last column shift to last column as displayed in attach pic
the imagebutton supposed to be in 2nd last column
shift right
</asp:GridView>
                 <asp:GridView ID="gvClaimSummary"  HeaderStyle-BackColor="#B8A9DC"
                  AlternatingRowStyle-BackColor="#E4E0EE" HeaderStyle-ForeColor="White" 
                         BorderColor="Black" BorderWidth="1px" Width="1100px"
                         RowStyle-VerticalAlign="Top" AllowPaging="true" PageSize="10"
                  AutoGenerateColumns="false" runat="server"  
                          onrowdatabound="gvClaimSummary_RowDataBound" 
                        onpageindexchanging="gvClaimSummary_PageIndexChanging" 
                        onrowcommand="gvClaimSummary_RowCommand" onrowcreated="gvClaimSummary_RowCreated" 
                        >
                   <Columns>
                  
                  <asp:BoundField HeaderText="Date" DataField="Datecreated" 
                                      HeaderStyle-Width="20%"
                                      ReadOnly="True"  
                                    HeaderStyle-HorizontalAlign="Left"  ItemStyle-HorizontalAlign="Left">
                                    <HeaderStyle  ForeColor="White"></HeaderStyle>
                                    
                                </asp:BoundField>
                               
                                                  
                                <asp:TemplateField HeaderStyle-Width="100px" HeaderText="Category">
                                     <ItemTemplate>
                                     <asp:Panel ID="pnl01" runat="server">
                                        <asp:Label ID="lbcategory" runat="server" Visible='<%# getMultipleVisibility(Eval("Category").ToString()) %>' Text='<%# Eval("Category") + "(+)" %>' />
                                        
                                        </asp:Panel>
                                                                              <br />
                                         <asp:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" runat="server" ExpandControlID="pnl01" CollapseControlID="pnl01" TargetControlID="panelmultiplecategory" Collapsed="true"></asp:CollapsiblePanelExtender>    
                                     
                                     <asp:Panel ID="panelmultiplecategory" runat="server"> 
                                         <asp:GridView ID="gvClaimSummaryMini" HeaderStyle-BackColor="#B8A9DC" 
                                          AlternatingRowStyle-BackColor="#E4E0EE" HeaderStyle-ForeColor="White" 
                                                 BorderColor="Black" BorderWidth="1px" Width="810px" 
                                                 RowStyle-VerticalAlign="Top" AllowPaging="true" PageSize="10" 
                                          AutoGenerateColumns="false" runat="server">
                                          <Columns>
                                            <asp:BoundField DataField="Categoryname" HeaderText="Category" HeaderStyle-Width="32%" ReadOnly="true" />
                                            <asp:BoundField DataField="Description" HeaderText="Description" HeaderStyle-Width="29%" ReadOnly="true" />
                                            <asp:BoundField DataField="Details" HeaderText="Details" HeaderStyle-Width="21%" ReadOnly="true" />                                                                   <asp:BoundField DataField="Amount" HeaderText="Amount" HeaderStyle-Width="28%" ReadOnly="true" />                       
                                          </Columns>
                                         </asp:GridView>
                                     
                                     </asp:Panel>
                                     
                                     </ItemTemplate>
                                </asp:TemplateField>
                                                                                               
                                 
                                                                   
                                 <asp:BoundField HeaderText="Description" DataField="Description" 
                                      HeaderStyle-Width="20%"
                                     ReadOnly="True"  
                                    HeaderStyle-HorizontalAlign="Left"  ItemStyle-HorizontalAlign="Left">
                                    <HeaderStyle  ForeColor="White"></HeaderStyle>
                                    
                                </asp:BoundField> 
                                
                                 <asp:BoundField HeaderText="Details" DataField="Detail" 
                                      HeaderStyle-Width="20%"
                                     ReadOnly="True"  
                                    HeaderStyle-HorizontalAlign="Left"  ItemStyle-HorizontalAlign="Left">
                                    <HeaderStyle  ForeColor="White"></HeaderStyle>
                                    
                                </asp:BoundField> 
                                
                                 <asp:BoundField HeaderText="Subtotal" DataField="Subtotal" 
                                      HeaderStyle-Width="20%"
                                     ReadOnly="True"  
                                    HeaderStyle-HorizontalAlign="Left"  ItemStyle-HorizontalAlign="Left">
                                    <HeaderStyle  ForeColor="White"></HeaderStyle>
                                    
                                </asp:BoundField> 
                                
                          
                                <asp:TemplateField HeaderStyle-Width="10%">
                                     <ItemTemplate>
                                            <span style="float:right; padding-right:20px;">
                                                <asp:LinkButton ID="hledit5" runat="server" CssClass="viewbutton" CommandName="EDITCLAIMSUMMARY" CommandArgument='<%# (Container as GridViewRow).RowIndex %>'></asp:LinkButton>
                                                <asp:Label ID="lblID3Field" Visible="false" Text='<%# Eval("UCSID") %>' runat="server" />
                                                <asp:Label ID="lblCateField" Visible="false" Text='<%# Eval("Category") %>' runat="server" />
                                            </span>
                                        </ItemTemplate>
                                         <HeaderTemplate>
                                        <span style="float:right; padding-right:12px;">
                                         <asp:Label ID="lblheader22" runat="server" Text="View" Font-Names="Arial"  ForeColor="White" />
                                        </span>
                                    </HeaderTemplate>
                                        
                                </asp:TemplateField>
                                
                                <asp:TemplateField HeaderStyle-Width="10%">
                                     <ItemTemplate>
                                            <span style="float:right; padding-right:20px;">
                                                <asp:LinkButton ID="hldeletelevel4" runat="server" CssClass="deletebutton" CommandName="DELETECLAIMSUMMARY" CommandArgument='<%# (Container as GridViewRow).RowIndex %>'></asp:LinkButton>
                                                <asp:Label ID="lblID2Field" Visible="false" Text='<%# Eval("UCSID") %>' runat="server" />
                                            </span>
                                        </ItemTemplate>
                                         <HeaderTemplate>
                                        <span style="float:right; padding-right:12px;">
                                         <asp:Label ID="lblheader24" runat="server" Text="Delete" Font-Names="Arial"  ForeColor="White" />
                                        </span>
                                    </HeaderTemplate>
                                        
                                </asp:TemplateField>
                                
                                
                                
                                
                                
                                
                  </Columns>
                  
                </asp:GridView>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
try doing one of the following:
1) Reverse your removal order
e.Row.Cells.RemoveAt(4);
e.Row.Cells.RemoveAt(3);
e.Row.Cells.RemoveAt(2);
e.Row.Cells[1].ColumnSpan = 4;

2) remove element 2 3 times
e.Row.Cells.RemoveAt(2);
e.Row.Cells.RemoveAt(2);
e.Row.Cells.RemoveAt(2);
e.Row.Cells[1].ColumnSpan = 4;

Author

Commented:
o.O

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial