• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1204
  • Last Modified:

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

0
Gaiala
Asked:
Gaiala
  • 2
1 Solution
 
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
 
GaialaAuthor Commented:
thank you very much!!!
:-)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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