日期:2014-05-17 浏览次数:20489 次
#region 记录CheckBox状态 //声明一个Dictionary(并将其表明为ViewState属性), //其中Key值(string)代表User的ID(数据库中的主键),Value值(bool)表示该行的CheckBox是否选中 public Dictionary<string, bool> CheckBoxState { get { return (ViewState["CheckBoxState"] != null) ? (Dictionary<string, bool>)ViewState["CheckBoxState"] : null; } set { ViewState["CheckBoxState"] = value; } } public T03_OrderInfoCollection Orders { get { return (Session["Collections"] != null) ? (T03_OrderInfoCollection)(Session["Collections"]) : null; } set { Session["Collections"] = value; } } //初始化Dictionary protected Dictionary<string, bool> InitializeUsersDic(T03_OrderInfoCollection collections) { Dictionary<string, bool> currentDic = new Dictionary<string, bool>(); //将集合中的主键内容存储到Dictionary中 foreach (T03_OrderInfo collection in collections) { currentDic.Add(collection.OrderInfoNum, false); } return currentDic; } #endregion
------解决方案--------------------
第一次数据绑定给列表的时候要初始化
//初始化所有数据的CheckBox状态为false
CheckBoxState = InitializeUsersDic(collections);