checklistBox默认选中多个选项

       //绑定全部的年级信息
        DataTable dtGrade = new GradeBLL().QueryAllActiveGrade();
        chblGrade.DataSource = dtGrade;
        chblGrade.DataTextField = "GradeName";
        chblGrade.DataValueField = "GradeID";
        chblGrade.DataBind();
        //获取已经选中的年级信息
        RoundGradeEntity enRoundGradeInfo = new RoundGradeEntity();
        enRoundGradeInfo.ID = dtRoundBasic.Rows[0]["ID"].ToString();
        //查询
        string strIndex;
        DataTable dtGradeSelected = round.QueryAllGradeByRoundID(enRoundGradeInfo);
        //根据从数据库中取出的数据,勾选选项
        for (int i = 0; i < chblGrade.Items.Count; i++)
        {
            for (int j = 0; j < dtGradeSelected.Rows.Count; j++)
            {
                strIndex = dtGradeSelected.Rows[j]["GradeID"].ToString().Trim();
                if (chblGrade.Items[i].Value.Trim()==strIndex)
                {
                    chblGrade.Items[i].Selected = true;
                }
            }
        }

你可能感兴趣的:(checklistBox默认选中多个选项)