因为工作的需要,需要DataGrid当中的两列进行求积运算,因此写了这个小算法!希望可以帮助一些人!
在求积的时候一定要先把里面的项转化成相应的类型,否则程序会报错!如果是小数或者金钱的话就要用到相应的类型
系我本人原创,转载请说明出处!
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
...{
foreach (DataGridItem di in this.DataGrid1.Items)
...{
if(di.ItemType == ListItemType.Item || di.ItemType == ListItemType.AlternatingItem)
...{
int a = int.Parse(di.Cells[0].Text.ToString());
decimal b = decimal.Parse(di.Cells[1].Text.ToString());
di.Cells[2].Text = Convert.ToDecimal((a*b).ToString()).ToString();
}
}
}
本文介绍在DataGrid中实现两列数值求积的方法,强调需先转换数据类型以避免程序错误,特别是处理小数或金钱数据时。这是一个解决实际工作需求的算法分享。
1491

被折叠的 条评论
为什么被折叠?



