private void filltable()
        {
            DataTable  StudentMark = new DataTable();
            DataColumn idStudent   = new DataColumn("id", Type.GetType("System.Int32"));
            DataColumn FIOstudent  = new DataColumn("Фамилия Имя", Type.GetType("System.String"));
            DataColumn idMark      = new DataColumn("idMark", Type.GetType("System.Int32"));
            DataColumn Mark        = new DataColumn("Оценка", Type.GetType("System.String"));

            StudentMark.Columns.Add(idStudent);
            StudentMark.Columns.Add(FIOstudent);
            StudentMark.Columns.Add(idMark);
            StudentMark.Columns.Add(Mark);
            List <Student> stud = DBobjects.Entities.Student.Where(p => p.idGroup == idGroup).ToList();

            foreach (Student st in stud)
            {
                if (DBobjects.Entities.ListMarkStud.Where(p => p.idStudent == st.idStudent && p.idFinalGrade == finalGrade.idFinalGrade).Count() > 0)
                {
                    ListMarkStud listMarkStud = DBobjects.Entities.ListMarkStud.FirstOrDefault(p => p.idStudent == st.idStudent && p.idFinalGrade == finalGrade.idFinalGrade);
                    StudentMark.Rows.Add(st.idStudent, st, listMarkStud.idListMarkStudent, listMarkStud.grade);
                }
                else
                {
                    StudentMark.Rows.Add(st.idStudent, st, 0, "");
                }
            }
            dataGridViewMark.DataSource          = StudentMark;
            dataGridViewMark.Columns[0].Visible  = false;
            dataGridViewMark.Columns[2].Visible  = false;
            dataGridViewMark.Columns[1].ReadOnly = true;
        }
 private void saveMark()
 {
     foreach (DataGridViewRow dgvr in dataGridViewMark.Rows)
     {
         if (Convert.ToInt32(dgvr.Cells[2].Value) == 0)
         {
             listMarkStud = new ListMarkStud();
         }
         else
         {
             int id = Convert.ToInt32(dgvr.Cells[2].Value);
             listMarkStud = DBobjects.Entities.ListMarkStud.FirstOrDefault(p => p.idListMarkStudent == id);
         }
         listMarkStud.grade        = dgvr.Cells[3].Value.ToString();
         listMarkStud.idStudent    = Convert.ToInt32(dgvr.Cells[0].Value);
         listMarkStud.idFinalGrade = finalGrade.idFinalGrade;
         if (DBobjects.Entities.ListMarkStud.Where(p => p.idListMarkStudent == listMarkStud.idListMarkStudent).Count() == 0)
         {
             DBobjects.Entities.ListMarkStud.Add(listMarkStud);
         }
         DBobjects.Entities.SaveChanges();
         fillDiscKontrol();
     }
 }