CheckBoxList 控件返回数据库如何设定选中项

解决方案 »

  1.   

    用循环。
      #region WebSite
            private void GetProductWebSite(long p_ID, CheckBoxList cbl)
            {
                if (cbl == null || cbl.Items.Count == 0) return;
                int temp = 0;
                for (int i = 0; i < cbl.Items.Count; i++)
                {
                    temp = 0;
                    temp = SQLParser.IntParse(cbl.Items[i].Value); ;
                    if (temp > 0)  { cbl.Items[i].Selected = true; }
                }
            }
            #endregion #region WebSite
            private void SetProductWebSite(long p_ID, CheckBoxList cbl)
            {
                if (cbl == null || cbl.Items.Count == 0) return;
                for (int i = 0; i < cbl.Items.Count; i++)
                {
                    if (cbl.Items[i].Selected)
                    {
                       
                        SiteID = SQLParser.IntParse(cbl.Items[i].Value);
                        
                    }
                }
            }
            #endregion