2
Reply

Variable is not adding in the GridView RowBound function

Nitol Biswas

Nitol Biswas

Dec 12 2016 4:41 AM
256
I want to add the openingBalace value in GridView1 GridView1_RowDataBoun() function. But it is not working. How can I do this. Please help.  Here is my Code : - 
 
long totalIncome = 0;
long totalExpense = 0;
long openingBalace;
public void gridview2_rowdatabound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
totalIncome += Convert.ToInt64(DataBinder.Eval(e.Row.DataItem, "income"));
totalExpense += Convert.ToInt64(DataBinder.Eval(e.Row.DataItem, "expense"));
openingBalace = totalIncome - totalExpense;
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
lblOpeningBalance.Text = openingBalace.ToString();
}
else
{
lblOpeningBalance.Text = "0";
}
}
 
 
long totalReceived = 0;
long totalPayment = 0;
long TotalBalace = 0;
long sum = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
totalReceived += Convert.ToInt64(DataBinder.Eval(e.Row.DataItem, "income"));
totalPayment += Convert.ToInt64(DataBinder.Eval(e.Row.DataItem, "expense"));
TotalBalace = totalReceived - totalPayment;
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
lblTotalReceive.Text = totalReceived.ToString();
lblTotalPayment.Text = totalPayment.ToString();
lblBalance.Text = TotalBalace.ToString();
}
else
{
lblTotalReceive.Text = "0";
lblTotalPayment.Text = "0";
lblBalance.Text = "0";
}
if (e.Row.RowType == DataControlRowType.DataRow)
 //Here I want to add the Variable
sum = openingBalace + Convert.ToInt64(DataBinder.Eval(e.Row.DataItem, "income")) -
Convert.ToInt64(DataBinder.Eval(e.Row.DataItem, "expense")) + sum;
e.Row.Cells[8].Text = sum.ToString();
}
}
 

Answers (2)