Solved

Programmatically Create GridView

Posted on 2008-06-20
4
1,669 Views
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"
                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
Comment
Question by:G0ggy
4 Comments
 
LVL 33

Accepted Solution

by:
raterus earned 500 total points
ID: 21831951
You are never setting,

gvwGroups.DataSource = (...)
0
 
LVL 14

Expert Comment

by:raja_ind82
ID: 21841108
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

828 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