Nurul Nurul - 1 month ago 8
Vb.net Question

VB.net how to create table using xml and displaying the table on the webpage

Can somebody please help me to amend this code because i tried running but the table didnt appear on the page. I'm new to XML and somebody gave me this snippet saying that XML coding is more reliable for tables.

The code probably works but i dont know how to display it to the page. I tried searching but i saw that many also did nearly the same thing but why didnt it work for me? While, some others made another xml file to keep the data, but in my case, i'm actually planning to retrieve data from a MS SQL 2005 database and display it in a table. What am i missing here?

Dim dt As DataTable = Me.GetData()
For Each row As DataRow In dt.Rows
Dim tr As XElement = <tr></tr>

For Each column In dt.Columns
Dim td As XElement = <td></td>
td.Value = row(column.Ordinal).ToString()

tr.Add(td)
Next

table.Add(tr)
Next

Answer
 Public Function DrawTable() As XElement
    Dim dt As DataTable = Me.GetData()
    Dim table As XElement = <table></table>
    Dim tr As XElement = <tr></tr>
    Dim td As XElement = <td></td>

    For Each row As DataRow In dt.Rows
        For Each column In dt.Columns
            td.Value = row(column.Ordinal).ToString()
            tr.Add(td)
        Next

        table.Add(tr)
    Next
    Return table
End Function

use this in your .aspx page will render Table

    <%= DrawTable()%>