Answered by:
Gridview Problem

Question
-
Sir this is my gridview i want both side sum dynamically in autogenrated column in gridview footer column Total and in(Grand Total) when i don't have column name
please help me
id date bno raj mohan ankit pramod Total
1 20/12 1 20 25 30 60
2 20/12 2 10 30 35 80
3 10/12 3 20 40 50 89
Grand Total:
- Edited by 0pramod Wednesday, April 10, 2013 7:24 AM
Wednesday, April 10, 2013 6:53 AM
Answers
-
Please use FooterRow by enabling it and see the sample:
http://msdn.microsoft.com/en-us/library/ms972833.aspx
PS: any problem related to asp.net, plz send here:
forums.asp.net
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & CatsWednesday, April 10, 2013 7:17 AM -
Hi,
go through this link for summery information in footer and for total in last column it will be better if you can do it in the datasource itself.
If you are using DataTable then insert a new column in the DataTable and insert sum of each column in the last Total sum.
For adding column in DataTable you can follow this link.
One good question is equivalent to ten best answers.
- Marked as answer by Bob Shen Tuesday, April 23, 2013 10:44 AM
Wednesday, April 10, 2013 8:37 AM -
Hi,
Use the following link for total in footer :
http://www.aspdotnet-suresh.com/2011/02/how-to-display-sum-of-columns-total-in.html
And total in column as you given above after pramod total you can use RowDataBound event as given below.
Take one label in last column where you want to show total and then
decimal sumFooterValue = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int lblRaj= ((Label)e.Row.FindControl("Label2")).Text;
int lblMohan= ((Label)e.Row.FindControl("Label3")).Text;
int lblAnkit= ((Label)e.Row.FindControl("Label4")).Text;
int lblPramod= ((Label)e.Row.FindControl("Label5")).Text;
int lblTotal = lblRaj+lblMohan+lblAnkit+lblPramod;
}Try it.
Good Luck
Thanks
Rajni
- Marked as answer by Bob Shen Tuesday, April 23, 2013 10:44 AM
Thursday, April 11, 2013 7:26 AM
All replies
-
Can you give some code snippet of your situation. That will make it easier to understand your problemWednesday, April 10, 2013 7:15 AM
-
Please use FooterRow by enabling it and see the sample:
http://msdn.microsoft.com/en-us/library/ms972833.aspx
PS: any problem related to asp.net, plz send here:
forums.asp.net
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & CatsWednesday, April 10, 2013 7:17 AM -
So, You need to display the Grand Total in the footer of the DataGridView.
Just add new row in the datagridview & calculate the sum of desired column value & display it in last row.
Int32 sum = 0; foreach (DataGridViewRow row in dataGridView1.Rows) {
string cellValue = Convert.ToString(row.Cells[0].Value); if (!string.IsNullOrEmpty(cellValue)) { sum += Convert.ToInt32(cellValue); } } dataGridView1.Rows.Add(1); dataGridView1.Rows[dataGridView1.RowCount-1].Cells[0].Value = sum;
Alternatively you can add a label to the end of datagridview & show the grand total.It all Happenz Sendil
- Proposed as answer by vasubabuk Wednesday, April 10, 2013 10:33 AM
Wednesday, April 10, 2013 7:38 AM -
Sir actually i want this in Gridview controlWednesday, April 10, 2013 7:49 AM
-
Sir actually i want this in Gridview control
Plz see my above link:)
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & CatsWednesday, April 10, 2013 8:33 AM -
Hi,
go through this link for summery information in footer and for total in last column it will be better if you can do it in the datasource itself.
If you are using DataTable then insert a new column in the DataTable and insert sum of each column in the last Total sum.
For adding column in DataTable you can follow this link.
One good question is equivalent to ten best answers.
- Marked as answer by Bob Shen Tuesday, April 23, 2013 10:44 AM
Wednesday, April 10, 2013 8:37 AM -
Hi,
Use the following link for total in footer :
http://www.aspdotnet-suresh.com/2011/02/how-to-display-sum-of-columns-total-in.html
And total in column as you given above after pramod total you can use RowDataBound event as given below.
Take one label in last column where you want to show total and then
decimal sumFooterValue = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int lblRaj= ((Label)e.Row.FindControl("Label2")).Text;
int lblMohan= ((Label)e.Row.FindControl("Label3")).Text;
int lblAnkit= ((Label)e.Row.FindControl("Label4")).Text;
int lblPramod= ((Label)e.Row.FindControl("Label5")).Text;
int lblTotal = lblRaj+lblMohan+lblAnkit+lblPramod;
}Try it.
Good Luck
Thanks
Rajni
- Marked as answer by Bob Shen Tuesday, April 23, 2013 10:44 AM
Thursday, April 11, 2013 7:26 AM