- ShowFooter="True"
- private double sum = 0;//取指定列的数据和,你要根据具体情况对待可能你要处理的是int
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowIndex >= 0)
- {
- sum += Convert.ToDouble(e.Row.Cells[5].Text)
- }
- if (e.Row.RowIndex >= 0)
- {
- sum += Convert.ToDouble(e.Row.Cells[5].Text);
- }
- else if (e.Row.RowType == DataControlRowType.Footer)
- {
- e.Row.Cells[4].Text = "总价格为:";
- e.Row.Cells[5].Text = sum.ToString();
- e.Row.Cells[2].Text = "平均价格为:";
- e.Row.Cells[3].Text = ((int)(sum / GridView1.Rows.Count)).ToString();
- }
- }
protected void gv_checkstatistics_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
TableCell cell = new TableCell();
cell.ColumnSpan = e.Row.Cells.Count;
cell.HorizontalAlign = HorizontalAlign.Right;
e.Row.Cells.Clear();
for (int i = 0; i < 7; i++)
{
e.Row.Cells.Add(new TableCell());
}
e.Row.Cells[1].Attributes.Add("colspan", "2");
e.Row.Cells[1].Text = mysum1.ToString();
e.Row.Cells[2].Attributes.Add("colspan", "2");
e.Row.Cells[2].Text = mysum3.ToString();
e.Row.Cells[3].Attributes.Add("colspan", "2");
e.Row.Cells[3].Text = mysum5.ToString();
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView myrows = (DataRowView)e.Row.DataItem;
if (!( + myrows[2].ToString() + myrows[2].ToString()).ToString().Contains('%'))
{
mysum1 += Convert.ToInt32(myrows[1].ToString()) + Convert.ToInt32(myrows[2].ToString());
mysum3 += Convert.ToInt32(myrows[3].ToString()) + Convert.ToInt32(myrows[4].ToString());
mysum5 += Convert.ToInt32(myrows[5].ToString()) + Convert.ToInt32(myrows[6].ToString());
}
}
}