Solved

ASP.net VB.net Add a table to a table

Posted on 2014-03-07
3
575 Views
Last Modified: 2014-03-07
I am getting the error
Use the "New" keyword to create an object instance
I am  trying to dynamically build a table and add it to another table cell
How do I alter the code to avoid this error

  Sub A
        Dim oTable As New Table
        oTable = oTableReport()
        Table2.Rows(0).Cells(0).Controls.Add(oTable)
End Sub


    Function oTableReport() As Table
        Try

            Dim rowCnt As Integer
            ' Current row count
            Dim rowCtr As Integer
            ' Total number of cells (columns).
            Dim cellCtr As Integer
            ' Current cell counter.
            Dim cellCnt As Integer
            Dim Table1 As New Table
            rowCnt = 2
            cellCnt = 3
            Table1.BorderWidth = 1
            Table1.BorderColor = Drawing.Color.Black
            Table1.BorderStyle = BorderStyle.Solid
            Table1.GridLines = GridLines.Both

            For rowCtr = 1 To rowCnt
                Dim tRow As New TableRow()
                For cellCtr = 1 To cellCnt
                    Dim tCell As New TableCell()
                    tCell.Text = "Row " & rowCtr & ", Cell " & cellCtr
                    ' Add new TableCell object to row.
                    tRow.Cells.Add(tCell)
                Next
                ' Add new row to table.
                Table1.Rows.Add(tRow)
                'Panel1.Controls.Add(Table1)
            Next
        Catch ex As Exception
            MsgBox(ex.Message & " rew33")
        End Try
    End Function
0
Comment
Question by:murbro
  • 2
3 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 39911977
try this

 Sub A
      Dim oTable As New Table
        oTable = oTableReport()
        Table2.Rows(0).Cells(0).Controls.Add(oTable)
End Sub
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 39911984
I tried this and working finr for me ... I have also added Return Table 1 in function

Dim oTable As New Table
        oTable = oTableReport()
        Table2.Rows(0).Cells(0).Controls.Add(oTable)


Function oTableReport() As Table
        Try

            Dim rowCnt As Integer
            ' Current row count
            Dim rowCtr As Integer
            ' Total number of cells (columns).
            Dim cellCtr As Integer
            ' Current cell counter.
            Dim cellCnt As Integer
            Dim Table1 As New Table
            rowCnt = 2
            cellCnt = 3
            Table1.BorderWidth = 1
            Table1.BorderColor = Drawing.Color.Black
            Table1.BorderStyle = BorderStyle.Solid
            Table1.GridLines = GridLines.Both

            For rowCtr = 1 To rowCnt
                Dim tRow As New TableRow()
                For cellCtr = 1 To cellCnt
                    Dim tCell As New TableCell()
                    tCell.Text = "Row " & rowCtr & ", Cell " & cellCtr
                    ' Add new TableCell object to row.
                    tRow.Cells.Add(tCell)
                Next
                ' Add new row to table.
                Table1.Rows.Add(tRow)
                'Panel1.Controls.Add(Table1)
            Next
            Return Table1
        Catch ex As Exception
            MsgBox(ex.Message & " rew33")
        End Try
    End Function
0
 

Author Closing Comment

by:murbro
ID: 39911992
Great. Worked well. Thanks very much
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

12 Experts available now in Live!

Get 1:1 Help Now