Thursday, May 8, 2008

total in datagrid footer

http://msdn.microsoft.com/en-us/library/ms972833.aspx
int onhandqty = 0;
int quantityTotal = 0;
int wk1qtyTot = 0;
int wk2qtyTot = 0;
int wk3qtyTot = 0;
protected void productsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// add the UnitPrice and QuantityTotal to the running total variables
onhandqty += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "On Hand Qty"));
quantityTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Ship Qty"));
wk1qtyTot += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Week1"));
wk2qtyTot += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Week2"));
wk3qtyTot += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Week3"));

}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[5].Text = "Totals:";
// for the Footer, display the running totals
e.Row.Cells[6].Text = onhandqty.ToString("d");
e.Row.Cells[7].Text = quantityTotal.ToString("d");
e.Row.Cells[8].Text = wk1qtyTot.ToString("d");
e.Row.Cells[9].Text = wk2qtyTot.ToString("d");
e.Row.Cells[10].Text = wk3qtyTot.ToString("d");

e.Row.Cells[5].HorizontalAlign = e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Left;
e.Row.Font.Bold = true;
}

www.visli.com

No comments: