protected void dgCourseSection_ItemCommand(object sender, System.Web.UI.WebControls.DataGridCommandEventArgs e) { CourseSection lec = new CourseSection(); if (e.CommandName == "AddCourseSection") { DropDownList txtTempCourseCode = (DropDownList)e.Item.Cells[0].FindControl("ddlCourseCodeNew"); TextBox txtTempSectionNo = (TextBox)e.Item.Cells[1].FindControl("txtSectionNoNew"); Regex sectionRegex = new Regex(@"^\d{1,5}$"); Match checkSection = sectionRegex.Match(txtTempSectionNo.Text); if (txtTempCourseCode.Text.Trim() == "") { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Please fill in the course code!', 'error')</script>'"); } else if (!checkSection.Success) { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Section number must be digit only', 'error')</script>'"); } else if (txtTempSectionNo.Text.Trim() == "") { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Please fill in the section number!', 'error')</script>'"); } else { if (lec.Add(txtTempCourseCode.Text, txtTempSectionNo.Text) == false) { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'This " + txtTempSectionNo.Text + " course section cannot have same section no, try another number!', 'error')</script>'"); } else { ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script type='text/javascript'>swal({title: 'Added!', text: 'This course section " + txtTempSectionNo.Text + " (" + txtTempCourseCode.Text + ") course section is added successfully', type : 'success', confirmButtonText : 'OK'}, function (isConfirm) { if (isConfirm) { window.location.href = 'cpCourseSection.aspx'; }});</script>'"); } } } else if (e.CommandName == "DeleteCourseSection") { Label rowCourseSectionID = (Label)e.Item.Cells[0].FindControl("lblID"); if (lec.DeleteCourseSection(rowCourseSectionID.Text) == false) { ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Delete this course section record unsuccessfully', 'error')</script>'"); } else { ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script type='text/javascript'>swal({title: 'Deleted!', text: 'Deleted this course section record successfully', type : 'success', confirmButtonText : 'OK'}, function (isConfirm) { if (isConfirm) { window.location.href = 'cpCourseSection.aspx'; }});</script>'"); } } }