dynamic tables with hyperlinks
<p>this is my first post on this forum. I want to build a table based on data in a recordset with a hyperlink that calls a method which takes the message id from the link and redirects to another page to view the message. I've tried HTMLAnchors, LinkButtons but none seem to work. Any help would be greatly appreciated.</p>

<pre><code>    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim iUserID As Integer
    Dim sMsgId, sMsgSubject, sMsgDateSent, sMsgRead, sMsgFrom, sFirstname As String
    iUserID = Session("UserID")
    Dim cn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ApplicationServices").ConnectionString)
    Dim cmd As New SqlCommand()
    Dim tblRow As TableRow
    Dim tblCell1 As TableCell
    Dim tblCell2 As TableCell
    Dim tblCell3 As TableCell
    Dim tblCell4 As TableCell

    tblRow = New TableRow

    tblCell1 = New TableCell
    tblCell1.Text = ""
    tblRow.Cells.Add(tblCell1)

    tblCell2 = New TableCell
    tblCell2.Text = "From"
    tblRow.Cells.Add(tblCell2)

    tblCell3 = New TableCell
    tblCell3.Text = "Subject"
    tblRow.Cells.Add(tblCell3)

    tblCell4 = New TableCell
    tblCell4.Text = "Received"
    tblRow.Cells.Add(tblCell4)

    tblMessages.Rows.Add(tblRow)

    tblCell1 = Nothing
    tblCell2 = Nothing
    tblCell3 = Nothing
    tblRow = Nothing

    cmd.CommandText = "SELECT msg.msg_id, msg.msg_usr_from, usr.usr_firstname, msg.msg_subject, msg.msg_date_sent, msg.msg_read FROM messages msg inner join users usr on msg.msg_usr_to = usr.usr_id WHERE msg.msg_usr_to='" &amp; iUserID &amp; "'"
    cmd.Connection = cn
    cn.Open()
    Dim r As SqlDataReader = cmd.ExecuteReader
    Dim objControl As Button


    While r.Read()
        tblCell1 = New TableCell
        tblCell2 = New TableCell
        tblCell3 = New TableCell
        tblCell4 = New TableCell
        tblRow = New TableRow
        sMsgId = CStr(r("msg_id"))
        sMsgFrom = CStr(r("msg_usr_from"))
        sFirstname = CStr(r("usr_firstname"))
        sMsgSubject = CStr(r("msg_subject"))
        sMsgDateSent = CStr(r("msg_date_sent"))
        sMsgRead = CStr(r("msg_read"))

        If sMsgRead = "N" Then
            tblCell1.Text = "&lt;img width=30px src=images/new_email.png&gt;"
        Else
            tblCell1.Text = "&lt;img width=30px src=images/email_open.png&gt;"
        End If

        Dim objLinkbutton As 

        tblRow.Cells.Add(tblCell1)
        tblCell2.Text = sFirstname
        tblRow.Cells.Add(tblCell2)
        tblCell3.controls.add(       HYPERLINK HERE!!!
        tblRow.Cells.Add(tblCell3)
        tblCell4.Text = FormatDateTime(sMsgDateSent, DateFormat.LongDate)
        tblRow.Cells.Add(tblCell4)
        If sMsgRead = "N" Then
            tblCell2.Font.Bold = True
            tblCell3.Font.Bold = True
            tblCell4.Font.Bold = True
        End If
        tblMessages.Rows.Add(tblRow)
        tblCell1 = Nothing
        tblCell2 = Nothing
        tblCell3 = Nothing
        tblCell4 = Nothing
        tblRow = Nothing
    End While

    r.Close()
    cn.Close()
    cn = Nothing
    r = Nothing
    cmd = Nothing
End Sub

Protected Sub viewmessage(messageid As String)
    Context.Items("messageid") = "messageid"
    Server.Transfer("viewmessage.aspx")
End Sub
End Class
</code></pre>
