protected void AddData() { sessionId = Convert.ToInt32(Session["sessionId"]); Collection <AttendanceCL> attendanceCL = new Collection <AttendanceCL>(); foreach (GridViewRow item in grdStudent.Rows) { int studentId = Convert.ToInt32(grdStudent.DataKeys[item.RowIndex].Value.ToString()); StudentCL studentCL = studentBLL.viewStudentById(studentId, sessionId); DropDownList ddlStudentLeaveType1 = item.FindControl("ddlGrdStudentLeaveType") as DropDownList; if (Convert.ToInt32(ddlStudentLeaveType1.SelectedValue) != -1) { attendanceCL.Add(new AttendanceCL() { classId = studentCL.classId, date = Convert.ToDateTime(txtDate.Text), dateCreated = DateTime.Now, dateModified = DateTime.Now, isDeleted = false, studentId = studentId, studentLeaveType = ddlStudentLeaveType1.SelectedItem.ToString(), studentLeaveTypeId = Convert.ToInt32(ddlStudentLeaveType1.SelectedValue), }); } } Collection <AttendanceCL> attendanceUpdated = attendanceBLL.addAttendance(attendanceCL); //lblUpdate.Text = attendanceUpdated.Count() + " Entries have been added. The page will refresh in 5 seconds"; //Response.AppendHeader("Refresh", "5;url=ManageAttendance.aspx?classId=" + attendanceUpdated[0].classId + "&date=" + attendanceUpdated[0].date); }