asp.net gridview with footer-how to delete an unwanted column

Hi,
I am trying to remove the last column on the gridview on my asp.net page. Since I've added some c# code to add up the sum of the columns another column has appeared on the gridview table which i cant get rid of.

Anyone know what i need to change?
Thanks
asp.net 
 
 <asp:GridView ID="gvwTimesheet" runat="server" AutoGenerateColumns="False" CssClass="gridTimesheet" ShowFooter="true"
                                 onRowDataBound="sumRows" onRowCreated="setFooter">
                                
                                   
                    <columns>
                        <asp:BoundField DataField="ClientName" HeaderText="Client name" />
                        <asp:BoundField DataField="ProjectName" HeaderText="Project name" />
                        <asp:BoundField DataField="EmployeeName" HeaderText="Employee name" />
                        <asp:BoundField DataField="Date" HeaderText="Date:" />
                       
                        <asp:templatefield headertext="Task">
                        <itemtemplate>
                            <%# Eval("Task") %>
                            <span class="tableLinks">
                            | <a href="EditTimesheet.aspx?ID=<%# Eval("ID") %>">Edit</a> 
                            </span>
                        </itemtemplate> 
                        </asp:templatefield>
                        <asp:BoundField DataField="Timespent" HeaderText="Timespent:" />
                        
            
                    </columns>
                </asp:GridView>
 
 
 
 
c#
 
 public void sumRows(Object src, GridViewRowEventArgs e)
    {
       
 
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TableCellCollection cells = e.Row.Cells;
            total += Int32.Parse(float.Parse(cells[cells.Count - 1].Text.Split(' ')[0]).ToString());
            cells[cells.Count - 1].Text = string.Format("{0:n}",
            float.Parse(cells[cells.Count - 1].Text.Split(' ')[0]));
        }
    }
 
    public void setFooter(Object src, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            TableCellCollection cells = e.Row.Cells;
            cells.RemoveAt(0); cells.RemoveAt(0);
            cells[0].ColumnSpan = 5;
            cells[0].Text = "Total";
            cells[1].Text = string.Format("{0:n}", total);
            cells[1].BackColor = System.Drawing.Color.Orange;
            
        }
 
 
    }

Open in new window

screenshottable.jpg
CharlieDevAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ARahimAwanCommented:
Problem is in setFooter Method. You need to Remove 4 columns and then set colspan of first column to 5. Following would work fine.

 public void setFooter(Object src, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            TableCellCollection cells = e.Row.Cells;
            cells.RemoveAt(0);
            cells.RemoveAt(0);
            cells.RemoveAt(0);
            cells.RemoveAt(0);        
           
            cells[0].ColumnSpan = 5;
            cells[0].Text = "Total";
            cells[1].Text = string.Format("{0:n}", total);
            cells[1].BackColor = System.Drawing.Color.Orange;
        }
    }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CharlieDevAuthor Commented:
Brilliant!! Thanks thats solved the problem
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.