不能使用带有的on while循环声明gridview复选框
一个班级SqlDataReader
?
protected void SelectedCourse()
{
var courseid = lblCourseid.Text == "" ? 0 :Convert.ToInt64(lblCourseid.Text);
var trimester = ddlTrimester.Text == "Select" ? 0 : Convert.ToInt64(ddlTrimester.Text);
SqlConnection con = new SqlConnection(dbFunctions.connection);
CheckBox cblCourseCode = (CheckBox)gvDetails.Rows[e.RowIndex].FindControl("cblCourseCode");
SqlCommand cmd =
new SqlCommand(@"SELECT
COURSE_DIST.COURSECD, COURSE_DIST.COURSETITLE,
COURSE_DIST.CREDIT, COURSE_DIST.COURSETP
FROM
COURSE_SELECTION
INNER JOIN
COURSE_DIST ON COURSE_SELECTION.COURSEID = COURSE_DIST.COURSEID
AND COURSE_SELECTION.TRIMESTER = COURSE_DIST.TRIMESTER
AND COURSE_SELECTION.COURSECD = COURSE_DIST.COURSECD
WHERE
COURSE_DIST.COURSEID = '" + courseid + "'
AND COURSE_DIST.TRIMESTER = " + trimester + "
AND COURSE_DIST.AYEAR = '" + ddlAcademicYear.Text + "'
AND COURSE_DIST.SESSION = '" + ddlSession.Text + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read() == true)
{
var coursecd = dr["COURSECD"].ToString();
cblCourseCode.Checked = coursecd;
cblCourseCode.Checked = true;
}
dr.Close();
con.Close();
}