Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1680
  • Last Modified:

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

0
G0ggy
Asked:
G0ggy
1 Solution
 
raterusCommented:
You are never setting,

gvwGroups.DataSource = (...)
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now