日期:2014-05-18  浏览次数:20429 次

关于gridview 合计及小计(在线等待.....)
在web中   把数据绑定gridview   上
实现   如下格式
名称         数据       单价       金额  
  a             b               c             d
a               c               d             f
小计         b+c     (c+d)/2         d+f
bc           d                   c           f
bc           c                   e           h
小计       d+c         (c+e)/2       f+h
总计       b+c+d+c                     d+f+f+h
请大家帮忙,
谢谢

------解决方案--------------------
舉個例子,在下面事件里面寫方法
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

ds 你綁定的數據源:
int count=0;
int count1 = 0 ;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
count += int.Parse(ds.Tables[0].Rows[i][ "数据 "].ToString());
count1 += int.Parse(ds.Tables[0].Rows[i][ "单价 "].ToString());
}
int sum = count;
int nAv = count1/ds.Tables[0].Rows.Count;

if (e.Row.RowType == DataControlRowType.Footer)//判定当前的行是否属于datarow最后一行

DataRowView view = (DataRowView)e.Row.DataItem;
TextBox ts= (TextBox)e.Row.FindControl( "textBox1 ");
ts.Text = "和為: "+sum.toString();
}
}
.......
------解决方案--------------------
你在数据库中 用视图写好了再绑定不就完了? 例:
SELECT dbo.AutoQuiz.QuizID, dbo.AutoQuiz.DealerID, dbo.AutoQuiz.Qtitle,

dbo.AutoQuiz.QuizDate, (dbo.AutoQuizBack.BackText+dbo.AutoQuizBack.BackDate) as 小计★★★★★★★


dbo.AutoQuizBack.DealerID AS DealerIDS
FROM dbo.AutoQuiz INNER JOIN
dbo.AutoDealer ON dbo.AutoQuiz.DealerID = dbo.AutoDealer.DealerID INNER JOIN
dbo.AutoQuizBack ON dbo.AutoQuiz.QuizID = dbo.AutoQuizBack.QuizID