C# 如何在gridview中求和从asp.net数据库中选择数据
我在asp.net中工作,我有一个网格视图,其中我从基本工资中找出pf和ESI值,我希望在Repues的gridview页脚中找到总pf和总ESI之和的正确解决方案,因此请帮助我您必须在gridview的RowDataBound事件中编写代码 我发布了一个示例代码供您参考,您自己试试吧C# 如何在gridview中求和从asp.net数据库中选择数据,c#,asp.net,gridview,C#,Asp.net,Gridview,我在asp.net中工作,我有一个网格视图,其中我从基本工资中找出pf和ESI值,我希望在Repues的gridview页脚中找到总pf和总ESI之和的正确解决方案,因此请帮助我您必须在gridview的RowDataBound事件中编写代码 我发布了一个示例代码供您参考,您自己试试吧 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == Dat
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");
}
}
也检查一下这个
请检查给定url的解决方案
也许你能找到你的解决办法
you can implement the code in RowDataBound Event of GridView