create placeholder programmatically and it to htmlTableRow

Hello,

I create GridViews programmatically. I have always added the GridView to a placeHolder which is set on default.aspx side.  Now I have a new requirement to put the created Gridviews into a html table. For that requirement I have to create html table programmatically.

So I thought to create a placeholder and html table on default.aspx.vb and then include the placeholder into the html table. So here is my code. The problem is that the gridviews are not visible :(

I hope you can help me. Thank you in advice.
Dim tblDetails As New HtmlTable
tblDetails.Visible = True
Dim tblCell As HtmlTableCell
Dim htmlR As HtmlTableRow
tblDetails.ID = "tblDet"
dim plH as new Placeholder
plH .ID = "pl" + strTOID
plH .Visible = True
myGrid.DataSource = clCreateGrid.load(strPath)
 
myGrid.DataBind()
plH .Controls.Add(myGrid)
tblDetails.Visible = True
tblCell = New HtmlTableCell
htmlR = New HtmlTableRow
 
tblCell.Controls.Add(plH)
                                                                htmlR.Controls.Add(tblCell)
tblDetails.Controls.Add(htmlR)

Open in new window

GaialaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

samtran0331Commented:
I don't see where you add the tblDetails to the page?
0
samtran0331Commented:
This worked for me, I made a fake function to replace your data function
codebehind:
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            Dim myGrid As New GridView
 
            Dim tblDetails As New HtmlTable
            Dim tblCell As HtmlTableCell
            Dim htmlR As HtmlTableRow
            tblDetails.ID = "tblDet"
 
            Dim plH As New PlaceHolder
            plH.ID = "plTest"
            plH.Visible = True
 
            myGrid.ID = "gvTest"
            myGrid.DataSource = clCreateGrid()
            myGrid.DataBind()
 
            plH.Controls.Add(myGrid)
            tblCell = New HtmlTableCell
            htmlR = New HtmlTableRow
 
            tblCell.Controls.Add(plH)
            htmlR.Controls.Add(tblCell)
            tblDetails.Controls.Add(htmlR)
 
            DirectCast(Me.Page.FindControl("Form1"), Control).Controls.Add(tblDetails)
 
        End If
    End Sub
    Private Function clCreateGrid() As DataTable
        'fake data to give some rows
        Dim dt As New DataTable
        Dim col As New DataColumn("MyColumn")
        dt.Columns.Add(col)
        For i As Integer = 0 To 9
            Dim r As DataRow
            r = dt.NewRow
            r.Item("MyColumn") = i
            dt.Rows.Add(r)
        Next
        Return dt
    End Function
 
aspx:
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GaialaAuthor Commented:
thank you very much!!!
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.