不同页面之间传值,通过checkbox来判断
功能:将A界面中选中的checkbox对应的记录的ID值传入B界面中,再更新所有ID值所在表中的字段State
操作:点击A中"生成"按钮后转到B,点击B中"保存"更新数据库
代码:
A中 .cs文件
protected void btnAdd_ServerClick(object sender, EventArgs e)
{
string
IDselected =
""
;
for
(
int
i = 0; i <= dgProXLList.Items.Count - 1; i++)
{
CheckBox
cb = (
CheckBox
)dgProXLList.Items[i].FindControl(
"checkbox"
);
if
(cb.Checked)
{
IDselected += dgProXLList.Items[i].Cells[0].Text +
";"
;
}
else
IDselected +=
""
;
}
Session[
"idSelected"
] = IDselected;
Server.Transfer(
"ProjectNewProduceOrder.aspx"
);
}
B中 .cs文件
protected void butSave_ServerClick(object sender, EventArgs e)
{
string id = Session["idSelected" ].ToString();
string[] str = id.Split(new char[] { ';' }, StringSplitOptions .RemoveEmptyEntries);
for (int j = 0; j < str.Length; j++)
{
string sql = "update OriOrder set State = '1' where OriOrderID = '" + str[j] +"'";
Database db = DatabaseFactory .CreateDatabase();
DBCommandWrapper cmd = db.GetSqlStringCommandWrapper(sql);
db.ExecuteNonQuery(cmd);
}
Session.Remove( "idSelected");
Response.Redirect( "ProjectProduceOrderCheck.aspx?ID={0}" ); //返回到 ProjectInfoManage.aspx 界面
}