Results 1 to 3 of 3

Thread: how to dynamically create hyperlinks at run-time?

  1. #1

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    how to dynamically create hyperlinks at run-time?

    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.
    "It's cold gin time again ..."

    Check out my website here.

  2. #2
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: how to dynamically create hyperlinks at run-time?

    VB Code:
    1. 'Declare Main table, row and cell
    2.         Dim tbl As New UI.WebControls.Table
    3.         Dim row As New UI.WebControls.TableRow
    4.         Dim cell As New UI.WebControls.TableCell
    5.  
    6.         'Declare inner table to hold links
    7.         Dim LnkTbl As New UI.WebControls.Table
    8.  
    9.         'Loop through DB records
    10.         For Index As Integer = 1 To 4
    11.             'Create new hyperlink control
    12.             Dim lnk As New UI.WebControls.HyperLink
    13.  
    14.             lnk.Text = "Link " & Index.ToString
    15.             lnk.NavigateUrl = "Woof.aspx?ID=" & Index.ToString
    16.  
    17.             'Create new cell and row and add new hyper link control to it
    18.             Dim LnkRow As New UI.WebControls.TableRow
    19.             Dim LnkCell As New UI.WebControls.TableCell
    20.  
    21.             LnkCell.Controls.Add(lnk)
    22.             LnkRow.Cells.Add(LnkCell)
    23.             LnkTbl.Rows.Add(LnkRow)
    24.         Next Index
    25.  
    26.         'Add link table to main table and add that to page
    27.         cell.Controls.Add(LnkTbl)
    28.         row.Cells.Add(cell)
    29.         tbl.Rows.Add(row)
    30.         Me.Controls.Add(tbl)
    Hope that helps.

    Woka

  3. #3

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: how to dynamically create hyperlinks at run-time?

    thank you, I'll check this out when I get a chance
    "It's cold gin time again ..."

    Check out my website here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width