Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation add rows to a html table

    Hi all

    Im trying pass data from a dataset into a html table ...but keep Getting the following exception !

    Value of type 'System.Data.Datarow' cannot be converted to 'System.Web.UI.Htmlcontrols.HtmltableRow'
    when adding rows to Table1 .....


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim MyDataset As DataSet
    Dim MyTable As New DataTable
    Dim i, numrows As Integer
    Dim sqlstr As String


    ' Fill a DataSet with data returned from the database.

    MyDataset = New DataSet
    MyDataset.ReadXml(Server.MapPath("XML/Kassestrimmel.xml"))

    ' Create a new DataTable object and assign to it
    ' the new table in the Tables collection.

    MyTable = MyDataset.Tables(0)


    ' Find how many rows are in the Rows collection
    ' of the new DataTable object.
    numrows = MyTable.Rows.Count
    If numrows = 0 Then
    Exit Sub
    Else

    For i = 0 To numrows - 1

    ' Print the values of the columns in the Columns
    ' collection for each row.
    Table2.Rows.Add(MyTable.Rows(i))'---------Value of type 'System.Data.Datarow' cannot be converted to 'System.Web.UI.Htmlcontrols.HtmltableRow'
    Next i
    End If

    End Sub

    hope someone got an idea ?

    thanks

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Each row has a cell, which holds the values. If I understand you correctly, try this out:
    Code:
    Dim i As Integer, x As Integer, numrows As Integer, cols As Integer
    MyTable = MyDataset.Tables(0)
    numrows = MyTable.Rows.Count
    cols = MyTable.Columns.Count
    For i = 0 To numrows - 1
    	Dim tblRow As TableRow = New TableRow
    	Table2.Rows.Add(tblRow)
    	For x = 0 To cols - 1
    		Dim tblCell As TableCell = New TableCell
    		tblRow.Cells.Add(tblCell)
    		tblCell.Text = MyTable.Rows(i).Item(x)
    	Next x
    Next i
    Good luck;
    Last edited by Brandoe85; 11-23-2005 at 05:22 AM.

  • #3
    New Coder
    Join Date
    Oct 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer

    Hi

    Thanks ....works just fine


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •