PDA

Click to See Complete Forum and Search --> : how to dynamically create hyperlinks at run-time?


BruceG
Oct 10th, 2005, 10:28 PM
Hello, I have a web form with a table consisting 1 row of 2 columns. In the left column, I want to dynamically generate a list of hyperlinks based on data in a database. (This is the main part of my question - if I can get that far, I'd be happy.) In the right column I have a placeholder control.

When the user clicks one of these links on the left (which will be to one of any number of html files), I want to display the contents of the linked file in the placeholder on the right.

Can anyone provide some ideas on how to do this? Any code or syntax would be helpful. Thanks.

Wokawidget
Oct 11th, 2005, 02:43 AM
'Declare Main table, row and cell
Dim tbl As New UI.WebControls.Table
Dim row As New UI.WebControls.TableRow
Dim cell As New UI.WebControls.TableCell

'Declare inner table to hold links
Dim LnkTbl As New UI.WebControls.Table

'Loop through DB records
For Index As Integer = 1 To 4
'Create new hyperlink control
Dim lnk As New UI.WebControls.HyperLink

lnk.Text = "Link " & Index.ToString
lnk.NavigateUrl = "Woof.aspx?ID=" & Index.ToString

'Create new cell and row and add new hyper link control to it
Dim LnkRow As New UI.WebControls.TableRow
Dim LnkCell As New UI.WebControls.TableCell

LnkCell.Controls.Add(lnk)
LnkRow.Cells.Add(LnkCell)
LnkTbl.Rows.Add(LnkRow)
Next Index

'Add link table to main table and add that to page
cell.Controls.Add(LnkTbl)
row.Cells.Add(cell)
tbl.Rows.Add(row)
Me.Controls.Add(tbl)

Hope that helps.

Woka

BruceG
Oct 11th, 2005, 06:53 AM
thank you, I'll check this out when I get a chance