protected void GridView1_RowDataBound( object sender, GridViewRowEventArgs e ) { if (e.Row.RowType == DataControlRowType.DataRow) { System.Data.Common.DbDataRecord db = (System.Data.Common.DbDataRecord)e.Row.DataItem; decimal c = Convert.ToDecimal(db["Score1"].ToString()); decimal d = Convert.ToDecimal(db["Score2"].ToString()); decimal t = c * Suser + d * Sexpert; Literal a = (Literal)e.Row.FindControl("totalScore"); a.Text = t.ToString(); } }
protected void GridView1_RowDataBound( object sender, GridViewRowEventArgs e ) { if (e.Row.RowType == DataControlRowType.DataRow) { System.Data.Common.DbDataRecord db = (System.Data.Common.DbDataRecord)e.Row.DataItem; decimal c = Convert.ToDecimal(db["number2"].ToString()); decimal d = Convert.ToDecimal(db["number1"].ToString()); decimal t = c + d ; Literal a = (Literal)e.Row.FindControl("totalScore"); a.Text = t.ToString(); } }
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Data.Common.DbDataRecord db = (System.Data.Common.DbDataRecord)e.Row.DataItem;
decimal c = Convert.ToDecimal(db["Score1"].ToString());
decimal d = Convert.ToDecimal(db["Score2"].ToString());
decimal t = c * Suser + d * Sexpert;
Literal a = (Literal)e.Row.FindControl("totalScore");
a.Text = t.ToString();
}
}
比如有一个数据表,其中字段和数据分别为:
tableid userid number1 number2
1 1 10 20
2 1 10 30
3 1 50 30怎样在GridView中显示“1”这个用户“number1”和“number2”分别的和?而不是分别显示。
然后在GridView中添加一个字段为“总和”,把“1”这个用户“number1”和“number2”总和
即
userid number1 number2 total
1 70 80 150在此多谢大家了
比如有一个数据表,其中字段和数据分别为:
tableid userid number1 number2
1 1 10 20
2 1 10 30
3 1 50 30怎样在GridView中显示“1”这个用户“number1”和“number2”分别的和?而不是分别显示。
然后在GridView中添加一个字段为“总和”,把“1”这个用户“number1”和“number2”总和
即
userid number1 number2 total
1 70 80 150在此多谢大家了
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Data.Common.DbDataRecord db = (System.Data.Common.DbDataRecord)e.Row.DataItem;
decimal c = Convert.ToDecimal(db["number2"].ToString());
decimal d = Convert.ToDecimal(db["number1"].ToString());
decimal t = c + d ;
Literal a = (Literal)e.Row.FindControl("totalScore");
a.Text = t.ToString();
}
}