Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在gridview中求和从asp.net数据库中选择数据_C#_Asp.net_Gridview - Fatal编程技术网

C# 如何在gridview中求和从asp.net数据库中选择数据

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

我在asp.net中工作,我有一个网格视图,其中我从基本工资中找出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");
   }
}
也检查一下这个

请检查给定url的解决方案

也许你能找到你的解决办法

  you can implement the code in RowDataBound Event of GridView