Link to home
Start Free TrialLog in
Avatar of G0ggy
G0ggyFlag for United Kingdom of Great Britain and Northern Ireland

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?
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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of raterus
raterus
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial