日期:2014-05-17 浏览次数:20474 次
public decimal ReturnTotal(int col)
{
decimal char_total = 0;
foreach (GridViewRow gvr in GridView1.Rows)
{
if (null != gvr.Cells[col].Text)
{
char_total += Convert.ToDecimal(gvr.Cells[col].Text);
}
}
return char_total;
}
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[2].Text = "小计";
e.Row.Cells[3].Text = ReturnTotal(3).ToString();
e.Row.Cells[4].Text = ReturnTotal(4).ToString();
e.Row.Cells[5].Text = ReturnTotal(5).ToString();
e.Row.Cells[7].Text = "合计:"+ Convert.ToString(ReturnTotal(3) + ReturnTotal(4) + ReturnTotal(5));
}
}
public decimal ReturnTotal(int col)
{
decimal char_total = 0;
foreach (GridViewRow gvr in GridView1.Rows)
{
if (null != gvr.Cells[col].Text && gvr.Cells[col].Text != "---")
{
char_total += Convert.ToDecimal(gvr.Cells[col].Text);
}
}
return char_total;
}
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType==DataControlRowType.DataRow)
{
e.Row.Cells[3].Text = e.Row.Cells[3].Text == "0.00" ? "---" : e.Row.Cells[3].Text;
e.Row.Cells[4].Text = e.Row.Cells[4].Text == "0.00" ? "---" : e.Row.Cells[4].Text;
e.Row.Cells[5].Text = e.Row.Cells[5].Text == "0.00" ? "---" : e.Row.Cells[5].Text;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[2].Text = "小计";
e.Row.Cells[3].Text = ReturnTotal(3).ToString();
e.Row.Cells[4].Text = ReturnTotal(4).ToString();
e.Row.Cells[5].Text = ReturnTotal(5).ToString();