G0ggy
asked on
Programmatically Create GridView
Hi all,
I'm trying to create a GridView for each row in a DataTable and add another DataTable's rows to it. There will be 1 GridView per parent DataTable. I have debugged and stepped through and can see the DataTable has rows, but the EmptyDataText is showing each time.
Can you see what is wrong?
I'm trying to create a GridView for each row in a DataTable and add another DataTable's rows to it. There will be 1 GridView per parent DataTable. I have debugged and stepped through and can see the DataTable has rows, but the EmptyDataText is showing each time.
Can you see what is wrong?
Protected Sub getForums()
Dim objFr As New groups()
Dim dt As DataTable = objFr.getGroups()
For Each groupRow As DataRow In dt.Rows
Dim gvwGroups As New GridView
gvwGroups.AutoGenerateColumns = False
gvwGroups.EmptyDataText = "There are no groups"
gvwGroups.Caption = groupRow("groupName").ToString
Dim dtForums As DataTable = getParentForumsForGroup(Convert.ToInt32(groupRow("groupID")))
For Each forumRow As DataRow In dtForums.Rows
Dim field As New BoundField
field.DataField = forumRow("forumName")
field.HeaderText = "Forum"
gvwGroups.Columns.Add(field)
Next
gvwGroups.DataBind()
pnlForums.Controls.Add(gvwGroups)
Next
End Sub
Private Function getParentForumsForGroup(ByVal groupID As Integer) As DataTable
Dim objFr As New forums()
Dim dt As DataTable = objFr.getParentForumsByGroupID(groupID)
Return dt
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
https://www.experts-exchange.com/questions/23013052/Programmatically-created-GridView-is-not-binding-the-data-to-the-grid-Why.html
https://www.experts-exchange.com/questions/22546219/Programmatically-created-gridview-vanishes-on-postback.html
https://www.experts-exchange.com/questions/23249566/Programmatically-Build-GridView.html
Regards,
M.Raja