Friday, 9 August 2013

C# .net Datagrid binding from different sources

C# .net Datagrid binding from different sources

I have a problem using Datagrid in C# .net.
I would like to print a two dimensional array in my application and be
able to add some columns. I would like to do something like that:
Student 1 Student 2
Maths ----------- 7 ----------- 5
History ----------- 6 ----------- 8
Then, I would like to be able to add other columns to enter the marks of
other students. My problem is that I store the mark in an object witch has
a mark field and when I do not succeed to bind each column with each
student's marks. Each time I try to do this, I have the same mark on each
row.
I tried to do something like that:
BoundColumn nameColumn = new BoundColumn();
nameColumn.DataField = "Mark";
nameColumn.DataFormatString = "{0}";
this.MarksDatagrid.Columns.Add(nameColumn);
this.MarksDatagrid.AutoGenerateColumns = false;
this.MarksDatagrid.DataSource = listToPrint;
this.MarksDatagrid.DataBind();
In listToPrint, I have an object with a student and his mark. Thanks a lot
for your help :)

No comments:

Post a Comment