Programmatically Create GridView

Posted on 2008-06-20
Last Modified: 2013-11-07
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"






    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

Question by:G0ggy
LVL 33

Accepted Solution

raterus earned 500 total points
Comment Utility
You are never setting,

gvwGroups.DataSource = (...)
LVL 14

Expert Comment

Comment Utility

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now