参考如下:
根据CheckBox选中的行取值:
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
CheckBox ckb = (CheckBox)this.GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (ckb.Checked)
{
huohao =Convert.ToInt32(this.GridView1.Rows[i].Cells[2].Text);
shuliang = Convert.ToInt32(this.GridView1.Rows[i].Cells[3].Text);
danjia =Convert.ToDecimal(this.GridView1.Rows[i].Cells[4].Text);
heJiJinE =Convert.ToDecimal(this.GridView1.Rows[i].Cells[5].Text);
jinhuoId =Convert.ToInt32(this.GridView1.Rows[i].Cells[7].Text);
}
}
计算数总数:
在Gridview的RowDataBound事件中:
string kucunNum = this.DropDownList1.SelectedItem.Text;
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView row = e.Row.DataItem as DataRowView;
if (!DBNull.Value.Equals(row["JinHuoShuliang"]))//注意DBNull
{
shopNumber += Convert.ToInt32(row["JinHuoShuliang"]);
}
}
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells.RemoveAt(3);
e.Row.Cells.RemoveAt(2);
e.Row.Cells[1].ColumnSpan = 3;
e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Right;
e.Row.Cells[1].Text = kucunNum + "的库存量是:" + shopNumber.ToString();
}