mcnewsw8
Programmer
- Feb 26, 2013
- 3
i need to to add debits and credits columns and display the sum in a balance column that will be a running total. the debits and credits values come from the databaes. balance is calculated on the fly.
Income Expense Balance
100 0 100
50 25 125
500 0 625
0 30 595
etc
i am using the code below to attempt to make this work. it looks good on the first page, but the counter gets off on the 2nd and 3rd page. when i click the back page it goofs things up even more. my variable x is just a class variable so i think i need a better way to deal with the running balance.
protected void dataAccting_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//int x = 0;
RepeaterItem item = e.Item;
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView row = e.Item.DataItem as DataRowView;
Literal income = (Literal)item.FindControl("lit_Income");
Literal expense = (Literal)item.FindControl("lit_Expense");
if (income.Text == "")
{ income.Text = "0"; }
if (expense.Text == "")
{ expense.Text = "0"; }
income.Text = income.Text.Replace("$", "");
expense.Text = expense.Text.Replace("$", "");
//decimal expense = Convert.ToDecimal(row["Expense"].ToString());
Label t = (Label)e.Item.FindControl("lblBalance");
x += Convert.ToDecimal(income.Text) - Convert.ToDecimal(expense.Text);
t.Text = x.ToString();
}
}
thanks for any help.
Income Expense Balance
100 0 100
50 25 125
500 0 625
0 30 595
etc
i am using the code below to attempt to make this work. it looks good on the first page, but the counter gets off on the 2nd and 3rd page. when i click the back page it goofs things up even more. my variable x is just a class variable so i think i need a better way to deal with the running balance.
protected void dataAccting_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//int x = 0;
RepeaterItem item = e.Item;
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView row = e.Item.DataItem as DataRowView;
Literal income = (Literal)item.FindControl("lit_Income");
Literal expense = (Literal)item.FindControl("lit_Expense");
if (income.Text == "")
{ income.Text = "0"; }
if (expense.Text == "")
{ expense.Text = "0"; }
income.Text = income.Text.Replace("$", "");
expense.Text = expense.Text.Replace("$", "");
//decimal expense = Convert.ToDecimal(row["Expense"].ToString());
Label t = (Label)e.Item.FindControl("lblBalance");
x += Convert.ToDecimal(income.Text) - Convert.ToDecimal(expense.Text);
t.Text = x.ToString();
}
}
thanks for any help.