calculate total rows of datagrid
i have table with following rows student_id, name, Balance now i want to calculate total balance at the bottom of datagridview,any a idea on how to do it
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj Kumar ChoudharyPosted Jun 13, 2015, 4:55 AM
foreach(DataRow Dr in _Tab.Rows)
{
float.TryParse(Dr["Balance "].ToString(), out Count);
Total+=Count;
}
Float Total=0;
{
float.TryParse(Dr.Cells[2].ToString(), out Count);
Total+=Count;
}
Manoj BhoirPosted Jun 13, 2015, 4:53 AM
int SumColumn = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow GVRow = e.Row;
if (GVRow.RowType == DataControlRowType.DataRow)
{
TableCell Cell = GVRow.Cells[SumColumn]; // index of cell
try
{
Int32 CellValue = Convert.ToInt32(Cell.Text);
Sum += CellValue;
}
catch
{
// ignore bad data
}
}
}
protected void GridView1_DataBound(object sender, EventArgs e)
{
GridView1.FooterRow.Cells[SumColumn].Text = Sum.ToString();
}
Alok UniyalPosted Jun 13, 2015, 4:23 AM