我在 asp.net 工作,我有一个 GridView ,在其中我可以从基本工资中找到 pf 和 ESI 值,我想要在 Repues 的 gridview 页脚中正确解决总 PF 和总 ESI 的总和,所以请帮助我
最佳答案
你必须在gridview的RowDataBound事件中编写代码。
我发布了一个示例代码供您引用,您自己尝试一下
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblPrice = (Label)e.Row.FindControl("lblPrice");
Label lblUnitsInStock = (Label)e.Row.FindControl("lblUnitsInStock");
decimal price = Decimal.Parse(lblPrice.Text);
decimal stock = Decimal.Parse(lblUnitsInStock.Text);
totalPrice += price;
totalStock += stock;
totalItems += 1;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblTotalPrice = (Label)e.Row.FindControl("lblTotalPrice");
Label lblTotalUnitsInStock = (Label)e.Row.FindControl("lblTotalUnitsInStock");
lblTotalPrice.Text = totalPrice.ToString();
lblTotalUnitsInStock.Text = totalStock.ToString();
lblAveragePrice.Text = (totalPrice / totalItems).ToString("F");
}
}
关于c# - 如何在gridview中求和从asp.net数据库中选择数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16456036/