...

View Full Version : add rows to a html table



vbturbo
11-21-2005, 10:53 AM
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 .....:mad:


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

Brandoe85
11-23-2005, 06:12 AM
Each row has a cell, which holds the values. If I understand you correctly, try this out:


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;

vbturbo
11-29-2005, 05:49 PM
Hi

Thanks ....works just fine :thumbsup: :thumbsup: :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum