I have a class named Student
public class Student
{
public string Name { get; set; }
public List<int> Marks { get; set; }
public Student()
{
}
}
and I need to bind a list of Student to GridView
List<Student> StudentList = new List<Student>();
Student stud = new Student();
stud.Name = "Scott";
List<int> marks = new List<int>();
marks.Add(10);
marks.Add(20);
marks.Add(30);
stud.Marks = marks;
StudentList.Add(stud);
Student stud1 = new Student();
stud1.Name = "Jon";
List<int> marks1 = new List<int>();
marks1.Add(10);
marks1.Add(20);
marks1.Add(30);
stud1.Marks = marks1;
StudentList.Add(stud1);
GridView1.DataSource = StudentList;
GridView1.DataBind();
The gridview shows the name field only. how I can show the list of marks also with name field. (In this all the students have same number of marks, means sometimes 3, or sometimes 5. etc.)
I need show gridview like this
Name Mark1 Mark2 Mark3
Scott 10 20 30
Jon 10 20 30
Example:
Code:
I do not test it