62,046
社区成员
发帖
与我相关
我的任务
分享
//将选中checkbox行Id记录到arrys数组中并存入session
private void GetChoiceSelectedCheckBox()
{
foreach (GridViewRow row in GridView1.Rows)
{
int index = (int)GridView1.DataKeys[row.RowIndex].Value;
bool result = ((CheckBox)row.FindControl("ck")).Checked;
if (result)
{
if (!(arrayList.Contains(index)))
{
arrayList.Add(index);
}
}
}
if (arrayList != null && arrayList.Count > 0)
{
Session["Choice"] = arrayList;
}
}
//还原选中的checkbox
private void RevertChoiceSelectedCheckBox()
{
ArrayList arrays = (ArrayList)Session["Choice"]; //获得选中checkbox行Id集合
if (arrays != null && arrays.Count > 0)
{
foreach (GridViewRow row in GridView1.Rows)
{
int index = (int)GridView1.DataKeys[row.RowIndex].Value;
if (arrays.Contains(index))
{
((CheckBox)row.FindControl("ck")).Checked = true;
}
}
}
}