CharlieDev
asked on
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
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;
}
}
screenshottable.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER