protected ArrayList CheckedItems
...{
get
...{
return (ViewState["CheckedID"] != null) ? (ArrayList)VIEwState["CheckedID"] : null;
}
set
...{
VIEwState["CheckedID"] = value;
}
}
protected void btnPass_Click(object sender, EventArgs e)
...{
DataAccess.BLL.Product bll = new DataAccess.BLL.Product();
DataAccess.Model.Product model = new DataAccess.Model.Product();
GetSelected();
string id = string.Empty;
foreach (object productID in this.CheckedItems)
...{
model = bll.GetModel(int.Parse(productID.ToString()));
model.State = 1;
bll.Update(model);
}
DataAccess.MessageBox.ReLoad();
}
protected void gvProduct_RowDataBound(object sender, GridVIEwRowEventArgs e)
...{
//回顯之前選中的情況
if (e.Row.RowType == DataControlRowType.DataRow && this.CheckedItems != null)
...{
DataRowView row = e.Row.DataItem as DataRowVIEw;
CheckBox cb = e.Row.Cells[1].FindControl("cbProduct") as CheckBox;
if (this.CheckedItems.Contains(row["ProductID"].ToString()))
cb.Checked = true;
else
cb.Checked = false;
}
}
protected void gvProduct_DataBinding(object sender, EventArgs e)
...{
GetSelected();
}
protected void GetSelected()
...{
ArrayList chekcedItems = null;
if (this.CheckedItems == null)
chekcedItems = new ArrayList();
else
chekcedItems = this.CheckedItems;
foreach (GridVIEwRow gvr in gvProduct.Rows)
...{
if (gvr.RowType == DataControlRowType.DataRow)
...{
string id = gvr.Cells[0].Text;
CheckBox cb = gvr.FindControl("cbProduct") as CheckBox;
if (chekcedItems.Contains(id) && !cb.Checked)
chekcedItems.Remove(id);
if (!chekcedItems.Contains(id) && cb.Checked)
chekcedItems.Add(id);
}
}
this.CheckedItems = chekcedItems;
}