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.
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Jun 13, 2015, 12:55 AM EDT
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;
}
Alok UniyalRank #8,369 · 223 reputationPosted Jun 13, 2015, 12:23 AM EDT
Manoj BhoirRank #599 · 4K reputationPosted Jun 13, 2015, 12:53 AM EDT
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();
}
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts