private void updateLP_Click(object sender, EventArgs e) { if (LearningPlanGridView.SelectedCells.Count > 0) { var startingYear = 0; try { startingYear = int.Parse(lpStartingYear.Text); } catch { } var plan = ((List <LearningPlan>)LearningPlanGridView.DataSource)[LearningPlanGridView.SelectedCells[0].RowIndex]; plan.name = lpName.Text; plan.speciality_code = lpSpecialityCode.Text; plan.speciality_name = lpSpecialityName.Text; plan.profile = lpProfile.Text; plan.starting_year = startingYear; plan.education_standard = lpEducationStandard.Text; plan.faculty_id = (int)lpFaculty.SelectedValue; lpRepo.update(plan, plan.id); RefreshLearningPlanList(); } }