![](/img/trans.png)
[英]GridView: how to increase value of a cell by one everytime at row updating?
[英]GridView : how to increase a value from a cell by one on row updating?
名为“ Haha”的列类型为int。 该单元格数据表中的默认值为0。 在行更新时,我想将值增加一。
因此,现在该单元格中的值为0。 如果我只是按下更新按钮,那么数据表中的值将为1,如果我再次更新,其值为2,依此类推。
我已经试过了这段代码,但是没有用,我的意思是什么都没有改变。
GridViewRow currentRow = ((GridView)sender).Rows[e.RowIndex];
String intColumnText = currentRow.Cells[2].Text; //assuming it's the first cell
int value;
if (int.TryParse(intColumnText, out value))
{
//if you want to increment that value and override the old
currentRow.Cells[2].Text = (value++).ToString();
}
}
谢谢
尝试这个
GridViewRow currentRow = ((GridView)sender).Rows[e.RowIndex];
String intColumnText = currentRow.Cells[2].Text; //assuming it's the first cell
int value;
if (int.TryParse(intColumnText, out value))
{
//if you want to increment that value and override the old
((DataTable)((GridView)sender).DataSource).Rows[CurrentRow.RowIndex][2]=(value +1).ToString();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.