2

I want to display a total in the GridView footer - nothing unusual there. I've followed the example on the Microsoft website, but it's not working:

<asp:GridView ID="gvTimeOverview" DataSourceID="sdsTimeOverview" AutoGenerateColumns="false" ShowFooter="true" CssClass="gridview" runat="server"> <Columns> <asp:BoundField DataField="DateTimeAdded" HeaderText="Date" DataFormatString="{0:dd/MM/yyyy}" /> <asp:BoundField DataField="DateTimeAdded" HeaderText="Time" DataFormatString="{0:HH:mm}" /> <asp:BoundField DataField="TimeToAdd" HeaderText="Mins Allocated" /> </Columns> </asp:GridView> 

Code:

protected void gvTimeOverview_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { totalMins += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "TimeToAdd")); } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[0].Text = "Totals:"; e.Row.Cells[1].Text = totalMins.ToString(); e.Row.ForeColor = Color.Black; } } 

Any idea why?

4
  • Is condition if (e.Row.RowType == DataControlRowType.Footer) ever passed? Commented Nov 15, 2011 at 12:52
  • 1
    Can you elaborate on the not working part ? Does totalMins have any value while debug ? Commented Nov 15, 2011 at 12:53
  • msdn.microsoft.com/en-us/library/ms972833.aspx Commented Nov 15, 2011 at 12:55
  • sll - no, a break point on that line is not hit, but I don't know why. Niranjan - that is the guide I followed. Commented Nov 15, 2011 at 13:00

1 Answer 1

4

Event handler is not attached.

<asp:GridView ID="gvTimeOverview" DataSourceID="sdsTimeOverview" AutoGenerateColumns="false" ShowFooter="true" CssClass="gridview" runat="server" onrowdatabound="gvTimeOverview_RowDataBound"> .... 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.