View Full Version : add rows to a html table

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

' 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

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 ?


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
For x = 0 To cols - 1
Dim tblCell As TableCell = New TableCell
tblCell.Text = MyTable.Rows(i).Item(x)
Next x
Next i

Good luck;

11-29-2005, 05:49 PM

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