TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Nitol Biswas
NA
173
28.3k
Variable is not adding in the GridView RowBound function
Dec 12 2016 4:41 AM
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();
}
}
Reply
Answers (
2
)
Read Image from local network on MVC 5
Poperty Error in MVC