我想计算GridView
总数,for
循环出了什么问题?
public void Bind()
{
//Assign the datasource to GridView
this.grdCart.DataSource = Get_Arealist();
//Databind the grid
this.grdCart.DataBind();
decimal a = 0, c = 0;
for (int i = 0; i <= (grdCart.Rows.Count); i++)
{
a = Convert.ToDecimal(grdCart.Rows[i].Cells[3].Text.ToString());
c = c + a; //storing total qty into variable
c++;
}
Label2.Text = c.ToString();
}
一个简单的更改就是调整以适应c = c + a
,c += a
但这不是您的问题。尝试这样更改代码:
public void Bind()
{
//Assign the datasource to GridView
this.grdCart.DataSource = Get_Arealist();
//Databind the grid
this.grdCart.DataBind();
decimal a = 0, c = 0;
for (int i = 0; i < grdCart.RowCount; i++)
{
a = Convert.ToDecimal(grdCart.Rows[i].Cells[3].Text.ToString());
c += a; //storing total qty into variable
}
Label2.Text = Convert.ToString(c);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句