GridView Examples for ASP.NET 2.0: Displaying GridView Summary Data in the Footer


decimal priceTotal = 0; int quantityTotal = 0; protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // add the UnitPrice and QuantityTotal to the running total variables priceTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, “ITEMS”)); quantityTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, “PCS”)); } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[0].Text = “Totals:”; // for the Footer, display the running totals e.Row.Cells[1].Text = priceTotal.ToString(“c”); e.Row.Cells[2].Text = quantityTotal.ToString(“d”); e.Row.Cells[1].HorizontalAlign = e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Right; e.Row.Font.Bold = true; } }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s