protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string id = GridViewExamInfo.DataKeys[e.RowIndex].Value.ToString(); bool success = dao.DeleteBody(id, 7); if (success) { Response.Write("<script>alert('删除成功!')</script>"); //刷新该页面 SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select exam.*,Course.name,ClassInfo.Name as'classname' from exam left join Course on Exam.Course=Course.ID join ClassInfo on exam.ClassInfo=ClassInfo.id", sqlConnection); DataSet dataSet = new DataSet(); GridViewExamInfo.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewExamInfo.DataSource = dataSet; GridViewExamInfo.DataBind(); sqlConnection.Close(); sqlConnection.Close(); } else { Response.Write("<script>alert('删除失败!')</script>"); } }
protected void Page_Load(object sender, EventArgs e) { SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select exam.*,Course.name,ClassInfo.Name as'classname' from exam left join Course on Exam.Course=Course.ID join ClassInfo on exam.ClassInfo=ClassInfo.id", sqlConnection); DataSet dataSet = new DataSet(); GridViewExamInfo.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewExamInfo.DataSource = dataSet; GridViewExamInfo.DataBind(); sqlConnection.Close(); }
protected void Page_Load(object sender, EventArgs e) { Teacher t = (Teacher)Session["teacher"]; SqlConnection sqlConnection = SqlTools.Connection(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(string.Format("select exam.*,Course.name,ClassInfo.Name as'classname' from exam left join Course on Exam.Course=Course.ID join ClassInfo on exam.ClassInfo=ClassInfo.id where course.ID in (select id from course where teacher='{0}')", t.ID1), sqlConnection); DataSet dataSet = new DataSet(); GridViewExamInfo.DataKeyNames = new string[] { "id" }; sqlDataAdapter.Fill(dataSet); GridViewExamInfo.DataSource = dataSet; GridViewExamInfo.DataBind(); sqlConnection.Close(); }