protected void addBtn_Click(object sender, EventArgs e) { //creating a new student string studentNumber = studentNumberTxt.Text; string studentName = studentNameTxt.Text; AlgonquinCollege.Registration.Entities.Student newStudent = new AlgonquinCollege.Registration.Entities.Student(studentNumber, studentName); //create a new course string index = (string)Session["selectedCourse"]; string selectedCourseName = DropDownList1.SelectedValue.ToString(); Course newCourse = new Course(index, selectedCourseName); //creating a list of academic records List <AcademicRecord> academicRecordList = new List <AcademicRecord>(); AcademicRecord newAcademicRecord = new AcademicRecord(newCourse, newStudent); newAcademicRecord.Grade = int.Parse(gradeTxt.Text); //adding course to list and session if (Session["academicRecordListSession"] == null) { academicRecordList.Add(newAcademicRecord); Session["academicRecordListSession"] = academicRecordList; } else { academicRecordList = (List <AcademicRecord>)Session["academicRecordListSession"]; academicRecordList.Add(newAcademicRecord); Session["academicRecordListSession"] = academicRecordList; } academicRecordList.Sort((p1, p2) => string.Compare(p1.Student.Name, p2.Student.Name, true)); //displaying table ShowStudentRecords(); studentNumberTxt.Text = ""; studentNameTxt.Text = ""; gradeTxt.Text = ""; }
protected void addBtn_Click(object sender, EventArgs e) { //creating a new student string studentNumber = studentNumberTxt.Text; string studentName = studentNameTxt.Text; AlgonquinCollege.Registration.Entities.Student newStudent = new AlgonquinCollege.Registration.Entities.Student(studentNumber, studentName); //create a new course string index = (string)Session["selectedCourse"]; string selectedCourseName = DropDownList1.SelectedValue.ToString(); Course newCourse = new Course(index, selectedCourseName); //creating a list of academic records List <AcademicRecord> academicRecordList = new List <AcademicRecord>(); AcademicRecord newAcademicRecord = new AcademicRecord(newCourse, newStudent); newAcademicRecord.Grade = int.Parse(gradeTxt.Text); //adding course to list and session if (Session["academicRecordListSession"] == null) { academicRecordList.Add(newAcademicRecord); Session["academicRecordListSession"] = academicRecordList; } else { academicRecordList = (List <AcademicRecord>)Session["academicRecordListSession"]; academicRecordList.Add(newAcademicRecord); Session["academicRecordListSession"] = academicRecordList; } //sorting list by name StudentCompareByName myComp = new StudentCompareByName(); academicRecordList.Sort(myComp); //displaying table foreach (AcademicRecord item in academicRecordList) { if (item.Course.CourseName == DropDownList1.Text) { TableRow row = new TableRow(); TableCell cell = new TableCell(); cell.Text = item.Student.Id.ToString(); row.Cells.Add(cell); cell = new TableCell(); cell.Text = item.Student.Name; row.Cells.Add(cell); cell = new TableCell(); cell.Text = item.Grade.ToString(); row.Cells.Add(cell); tableSort.Rows.Add(row); } } studentNumberTxt.Text = ""; studentNameTxt.Text = ""; gradeTxt.Text = ""; }