2015-04-04 18 views
0

解釋一下,我有一個帶有列的gridview:數量,單位值,總值和累計值。我需要將累積值列 添加以前的值到當前值。例如:gridview中的自動求和列

量unitary_value total_value accumulated_value

10 10.00 100.00 100.00

20 50.00 1,000.00 1,100.00

5 500.00 2,500.00 3,600.00

基本上它是向上。列值(累計值)取上一行的值並加到當前值上。

如果你能幫助你!

感謝您的關注。

回答

0
TextBox txtBox = (TextBox)rptr.Items[i].FindControl("amount"); 
int unitary_value = Convert.ToInt32(abc.unitary_value); 
total += Convert.ToInt32(txtBox.Text) * unitary_value; 
lblTotal.Text = String.Format("{0:#,###,###.##}", (object)total); 

abc引用您在gridview中使用的表格。創建該對象的實例並調用unitary_value的值。

希望這可能會給你一些幫助!

0
for (int i = 0; i < DGV.Rows.Count; i++) 
{ 
    DGV.Rows[i].Cells[3].Value= (Convert.ToInt32(DGV.Rows[i-1].Cells[3].Value)+Convert.ToInt32(DGV.Rows[i].Cells[2].Value)).ToString();  
}