protected void Page_Load(object sender, EventArgs e) { string CourseID = Session["SelectedCourseID"].ToString(); List <DAL.Lesson> lessonlist = CourseBl.getLessonList(CourseID).ToList(); Session["Lesson"] = lessonlist; if (lessonlist != null) { this.gvLesson.DataSource = lessonlist; this.gvLesson.DataBind(); } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('There's no lesson in this course.')", true); } }