I am trying to build a DataTable to populate a DataGrid in VB.NET.
The columns will be the username and then question from an exam.
Each row will be the answers by user for each question.
So it would look something like this:
Username | What is your favorite color? | What is your favorite book?
-------------------------------------------------------------------------
Joe Blue The Hobbit
Fred Red The Road
Jill Orange Old Mans War
I am getting all my questions and running through a loop to add to the columns like this:
Dim table As New DataTable
table.Columns.Add("Username", GetType(String))
For Each q In query
table.Columns.Add(q.question.Stem, GetType(String))
Next
myDg.DataSource = table
myDg.DataBind()
That works great and gives me a table that has the needed columns, but I am stuck as to how and get each users answer and put it under the appropriate column.
I tried adding rows in the same loop, but that just adds all of the answers under the first column.
Any help or ideas would be welcomed!
Thanks!