private void setDataSourceToGrid() { dgvStuSubSemConfig.AutoGenerateColumns = false; dgvStuSubSemConfig.DataSource = null; systemManager objsystemManager = new systemManager(); List <Student> lststuSemAllocationData = new List <Student>(); lststuSemAllocationData = objsystemManager.getStuSemDataToGrid(); stuSemAllocationData objstuSemAllocationData; List <stuSemAllocationData> lstStuSem = new List <stuSemAllocationData>(); foreach (var item in lststuSemAllocationData) { objstuSemAllocationData = new stuSemAllocationData(); objstuSemAllocationData.StuSemConfigID = item.StuSemConfigID; objstuSemAllocationData.StudentID = item.StudentID; objstuSemAllocationData.universityID = item.universityID; objstuSemAllocationData.FullName = item.FullName; objstuSemAllocationData.SemesterID = item.ObjSemesters.SemesterID; objstuSemAllocationData.SemesterCode = item.ObjSemesters.SemesterCode; objstuSemAllocationData.SemesterName = item.ObjSemesters.SemesterName; objstuSemAllocationData.SubjectID = item.ObjSubjects.SubjectID; objstuSemAllocationData.SubjectCode = item.ObjSubjects.SubjectCode; objstuSemAllocationData.SubjectName = item.ObjSubjects.SubjectName; lstStuSem.Add(objstuSemAllocationData); } dgvStuSubSemConfig.DataSource = lstStuSem; }