Solved

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

Posted on 2014-03-07
3
576 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

815 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