Jacob Stinson
Jacob Stinson

Reputation: 301

Populate HTML table from vb list

I am a beginner at HTML with vb. How do I go about using a list that I have populated that is returned by a vb funciton in a nother class to populate an html table in my html doc?

Upvotes: 0

Views: 549

Answers (1)

Karen Payne
Karen Payne

Reputation: 5157

Although we don't know what you want completely here is something that might be of assistance using xml literals and embedded expressions to create a html structure taken from a list.

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim Taxpayers As New List(Of Taxpayer) From {
            New Taxpayer With
            {.ID = 1, .FirstName = "Karen", .LastName = "Payne", .BirthDay = #9/24/1956#, .ZipCode = "22222"},
            New Taxpayer With
            {.ID = 2, .FirstName = "Bill", .LastName = "Smith", .BirthDay = #9/24/1964#, .ZipCode = "23456"}
        }

        Dim htmlContent As String =
            <html>
                <style type="text/css">     
                TD {background-color: green;color: #F0F8FF;padding-right:15px;}
                .THeader {background-color: Yellow;color: Black;}
            </style>
                <body>
                    <table border="0">
                        <tr>
                            <td class='THeader'>First</td>
                            <td class='THeader'>Last</td>
                            <td class='THeader'>Birthday</td>
                            <td class='THeader'>postal</td>
                        </tr>
                        <%= From tp In Taxpayers Select
                            <tr>
                                <td width="80px"><%= tp.FirstName %></td>
                                <td width="45px"><%= tp.LastName %></td>
                                <td width="40px"><%= tp.BirthDay.ToShortDateString %></td>
                                <td width="25px"><%= tp.ZipCode %></td>
                            </tr> %>
                    </table>
                </body>
            </html>.ToString

    End Sub
End Class
Public Class Taxpayer
    Public Property ID As Integer
    Public Property FirstName As String
    Public Property LastName As String
    Public Property BirthDay As Date
    Public Property ZipCode As String
    Public Sub New()

    End Sub

End Class

Upvotes: 1

Related Questions