2

我在 asp.net 工作,我有一个网格视图,在其中我从基本工资中找出 pf 和 ESI 值,我希望在 Repues 的 gridview 页脚中正确解决总 PF 和总 ESI 的总和所以请帮助我

4

2 回答 2

2

您必须在 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");
   }
}

也检查一下http://msdn.microsoft.com/en-us/library/ms972833.aspx

于 2013-05-09T06:52:58.927 回答
0
  you can implement the code in RowDataBound Event of GridView 

http://www.aspdotnet-suresh.com/2011/02/how-to-display-sum-of-columns-total-in.html

http://aspdotnetsubhash.blogspot.in/

http://www.ezzylearning.com/tutorial.aspx?tid=1676759

请检查给定网址的解决方案

可能是你找到你的解决方案............

于 2013-05-09T07:40:49.813 回答