zoukankan      html  css  js  c++  java
  • 用数组作checkboxlist数据源

    public partial class User_Expectations : System.Web.UI.Page
    {
        Guid _rubricId;
        Guid _courseId;
        Guid _gradeId;
        string _str;
        protected void Page_Load(object sender, EventArgs e)
        {
            _rubricId = new Guid(Request.QueryString["Rubric_id"].ToString());
            Rubric.BLL.Rubrics myBll = new Rubric.BLL.Rubrics();
            _courseId = new Guid(myBll.GetModel(_rubricId).CourseId.ToString());
            _gradeId = new Guid(myBll.GetModel(_rubricId).GradeId.ToString());
            if (!Page.IsPostBack)
            {
                CheckBoxList1Bind();
                CheckBoxList2Bind();
            }
        }
        protected void rbl_SelectedIndexChanged(object sender, EventArgs e)
        {
    
        }
        #region datalist绑定方法
        //private void dlDescription1Bind()
        //{
        //    Rubric.BLL.Expectations myBll = new Rubric.BLL.Expectations();
    
        //    if (rbl.Items[0].Selected)
        //    {
        //        _str = "CourseId='" + _courseId + "' and IsSpecific=0";
        //        DataSet ds = myBll.GetList(_str);
        //        dlDescription1.DataSource = ds;
        //        dlDescription1.DataBind();
        //    }
        //    else
        //    {
        //        _str = "GradeId='" + _gradeId + "' and IsSpecific=0";
        //        DataSet ds = myBll.GetList(_str);
        //        dlDescription1.DataSource = ds;
        //        dlDescription1.DataBind();
        //    }
    
        //} 
        #endregion
    
        #region CheckBoxList1数据绑定
        private void CheckBoxList1Bind()
        {
            Rubric.BLL.Expectations myBll = new Rubric.BLL.Expectations();
    
            if (rbl.Items[0].Selected)
            {
                _str = "CourseId='" + _courseId + "' and IsSpecific=0";
                DataSet ds = myBll.GetList(_str);
                CheckBoxList1.DataSource = ds;
                CheckBoxList1.DataTextField = "Description";
                CheckBoxList1.DataValueField = "ExpecId";
                CheckBoxList1.DataBind();
            }
            else
            {
                _str = "GradeId='" + _gradeId + "' and IsSpecific=0";
                DataSet ds = myBll.GetList(_str);
                CheckBoxList1.DataSource = ds;
                CheckBoxList1.DataTextField = "Description";
                CheckBoxList1.DataValueField = "ExpecId";
                CheckBoxList1.DataBind();
            }
    
        }
        #endregion
    
        #region CheckBoxList2数据绑定
        private void CheckBoxList2Bind()
        {
            Rubric.BLL.Expectations myBll = new Rubric.BLL.Expectations();
    
            if (rbl.Items[0].Selected)
            {
                _str = "CourseId='" + _courseId + "' and IsSpecific=1";
                DataSet ds = myBll.GetList(_str);
                CheckBoxList2.DataSource = ds;
                CheckBoxList2.DataTextField = "Description";
                CheckBoxList2.DataValueField = "ExpecId";
                CheckBoxList2.DataBind();
            }
            else
            {
                _str = "GradeId='" + _gradeId + "' and IsSpecific=1";
                DataSet ds = myBll.GetList(_str);
                CheckBoxList2.DataSource = ds;
                CheckBoxList2.DataTextField = "Description";
                CheckBoxList2.DataValueField = "ExpecId";
                CheckBoxList2.DataBind();
            }
    
        }
        #endregion
    
        #region datalist数据绑定
        //private void dlDescription2Bind()
        //{
        //    Rubric.BLL.Expectations myBll = new Rubric.BLL.Expectations();
    
        //    if (rbl.Items[0].Selected)
        //    {
        //        _str = "CourseId='" + _courseId + "' and IsSpecific=1";
        //        DataSet ds = myBll.GetList(_str);
        //        dlDescription2.DataSource = ds;
        //        dlDescription2.DataBind();
        //    }
        //    else
        //    {
        //        _str = "GradeId='" + _gradeId + "' and IsSpecific=1";
        //        DataSet ds = myBll.GetList(_str);
        //        dlDescription2.DataSource = ds;
        //        dlDescription2.DataBind();
        //    }
    
        //} 
        #endregion
        #region 测试用的
        ////添加选中项1
        //protected void btnAdd1_Click(object sender, EventArgs e)
        //{
    
        //    #region 没有用的
        //    //for (int i = 0; i < dlDescription1.Items.Count; i++)
        //    //{
        //    //    if (dlDescription1.Items[i].ItemType == ListItemType.SelectedItem)
        //    //    {
        //    //        CheckBox chk = (CheckBox)dlDescription1.Items[i].FindControl("chkItem");
        //    //        if (chk.Checked)
        //    //        {
        //    //            //Guid _expecId = new Guid(dlDescription1.DataKeys[i].ToString());
        //    //            //Rubric.BLL.Expectations myBll = new Rubric.BLL.Expectations();
    
        //    //            //DataSet ds = myBll.GetList("ExpecId='" + _expecId + "'");
        //    //            //dlSelected1.DataSource = ds;
        //    //            //dlSelected1.DataBind();
        //    //            Response.Write(chk.Text);
        //    //        }
        //    //    }
    
        //    //} 
        //    #endregion
    
        //    foreach (DataListItem myItem in dlDescription1.Items)
        //    {
        //        CheckBox chk = (CheckBox)myItem.FindControl("chkItem");
        //        if (chk.Checked)
        //        {
        //            Guid _expecId = new Guid(dlDescription1.DataKeys[myItem.ItemIndex].ToString());
        //            Rubric.BLL.Expectations myBll = new Rubric.BLL.Expectations();
    
        //            DataSet ds = myBll.GetList("ExpecId='" + _expecId + "'");
        //            dlSelected1.DataSource = ds;
    
        //            Response.Write(chk.Text);
        //        }
        //    }
        //    dlSelected1.DataBind();
        //} 
        #endregion
        /// 
        /// 将一般期望左边的添加到右边
        /// 
        #region 将左边的添加到右边
        //protected void Button1_Click(object sender, EventArgs e)
        //{
        //    //for (int i = 0; i < CheckBoxList1.Items.Count; i++)
        //    //{
        //    //    if (CheckBoxList1.Items[i].Selected)
        //    //    {
        //    //        Response.Write(CheckBoxList1.Items[i].Text.ToString());
        //    //        Guid _expecId = new Guid(CheckBoxList1.Items[i].Value.ToString());
        //    //        Rubric.BLL.Expectations myBll = new Rubric.BLL.Expectations();
        //    //        ListItem item = new ListItem();
        //    //        item.Text = myBll.GetModel(_expecId).Description.ToString(); ;
        //    //        item.Value = myBll.GetModel(_expecId).ExpecId.ToString();
        //    //        CheckBoxList2.Items.Add(item);
        //    //        CheckBoxList1.Items.Remove(item);
        //    //    }
        //    //}
        //}
        #endregion
        protected void btnAdd1_Click(object sender, EventArgs e)
        {
            int _count=int.Parse(CheckBoxList1.Items.Count.ToString());
            string[] arr=new string[_count];
    
            for (int i = 0; i < arr.Length;i++)
            {
                if (CheckBoxList1.Items[i].Selected)
                {
                    Guid _expecId = new Guid(CheckBoxList1.Items[i].Value.ToString());
                    Rubric.BLL.Expectations myBll = new Rubric.BLL.Expectations();
                    arr[i] = myBll.GetModel(_expecId).Description.ToString();
                   
                    CheckBoxList1.Items[i].Selected = false;
                    CheckBoxList12.DataValueField = myBll.GetModel(_expecId).ExpecId.ToString();
                    CheckBoxList12.Items.Add(arr[i].ToString());
                    //CheckBoxList1.Items.RemoveAt(i);//从集合中移除指定索引的listitem
                  //  CheckBoxList1.DataBind();
                  //  CheckBoxList12.DataBind();
                }
            }
            #region 测试代码
            //foreach (ListItem item in CheckBoxList1.Items)
            //{
            //    if (item.Selected)
            //    {
            //        Guid _expecId = new Guid(item.Value.ToString());
            //        Rubric.BLL.Expectations myBll = new Rubric.BLL.Expectations();
            //        item.Text = myBll.GetModel(_expecId).Description.ToString(); ;
            //        item.Value = myBll.GetModel(_expecId).ExpecId.ToString(); 
            //        CheckBoxList2.Items.Add(item);
            //        CheckBoxList1.Items.Remove(item);
            //    }
    
            //} 
            #endregion
            
        }
        //添加特殊期望到右边
        protected void btnAdd2_Click(object sender, EventArgs e)
        {
            int _count = int.Parse(CheckBoxList2.Items.Count.ToString());
            string[] arr = new string[_count];
    
            for (int i = 0; i < arr.Length; i++)
            {
                if (CheckBoxList2.Items[i].Selected)
                {
                    Guid _expecId = new Guid(CheckBoxList2.Items[i].Value.ToString());
                    Rubric.BLL.Expectations myBll = new Rubric.BLL.Expectations();
                    arr[i] = myBll.GetModel(_expecId).Description.ToString();
                    
                    CheckBoxList2.Items[i].Selected = false;
                    CheckBoxList22.DataValueField = myBll.GetModel(_expecId).ExpecId.ToString();
                    CheckBoxList22.Items.Add(arr[i].ToString());
                  //  CheckBoxList2.Items.RemoveAt(i);//从集合中移除指定索引的listitem
                }
            }
        }
        //移除选定的一般期望到左边
        protected void btnRemove1_Click(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < CheckBoxList22.Items.Count; i++)
                {
                    if (CheckBoxList12.Items[i].Selected)
                    {
    
                        CheckBoxList12.Items.RemoveAt(i);
                        CheckBoxList12.DataBind();
                    }
                }
            }
            catch
            {
                
            }
        }
        //移除选定的特殊期望到左边
        protected void btnRemove2_Click(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < CheckBoxList22.Items.Count; i++)
                {
                    if (CheckBoxList22.Items[i].Selected)
                    {
                        CheckBoxList22.Items.RemoveAt(i);
                        CheckBoxList22.DataBind();
                    }
                }
            }
            catch
            {
    
            }
            
        }
        //移除所有选中的一般期望
        protected void btnRemoveAll1_Click(object sender, EventArgs e)
        {
            CheckBoxList12.Items.Clear();
        }
        //移除所有选中的特殊期望
        protected void btnRemoveAll2_Click(object sender, EventArgs e)
        {
            CheckBoxList22.Items.Clear();
        }
        //
        protected void btnAdd_Click(object sender, EventArgs e)
        {
    
        }
    }
  • 相关阅读:
    如何利用WGET覆写已存在的档案
    linux 脚本返回值
    ubuntu的配置网络
    非交互模式修改Ubuntu密码的命令
    [zz]python多进程编程
    [zz]linux修改密码出现Authentication token manipulation error的解决办法
    [zz]4.1.5 进程的处理器亲和性和vCPU的绑定
    vcpu
    非交互式调用交互式程序
    HDOJ_ACM_饭卡
  • 原文地址:https://www.cnblogs.com/jianfangkk/p/1367189.html
Copyright © 2011-2022 走看看