Add dynamic hyperlink on the fly in ASP.NET

Discussion in 'ASP .Net' started by sweetpotatop@yahoo.com, Apr 21, 2006.

  1. Guest

    Hello,

    I would like to create dynamic hyperlinks in a web page when it is
    first loaded by using ASP.NET. Basically there will be a list of
    documents in a folder and I will list them all as a hyperlink for user
    access.

    I wonder how I can go through the folder and create the dynamic
    hyperlink on the fly in ASP.NET.

    Thanks in advance.
     
    , Apr 21, 2006
    #1
    1. Advertising

  2. Teemu Keiski Guest

    Hi,

    something like
    ***listfolder.aspx***

    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.IO" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs)
    If Not Page.IsPostBack Then
    'lists files in current folder
    rptFiles.DataSource = Directory.GetFiles(Server.MapPath("."))
    rptFiles.DataBind()

    End If
    End Sub

    Protected Sub rptFiles_ItemDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.RepeaterItemEventArgs)
    If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    ListItemType.AlternatingItem Then
    Dim strFile As String = Path.GetFileName(CStr(e.Item.DataItem))
    Dim hplFile As HyperLink =
    DirectCast(e.Item.FindControl("hplFile"), HyperLink)
    hplFile.Text = strFile
    hplFile.NavigateUrl = strFile
    End If
    End Sub
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:Repeater ID="rptFiles" runat="server"
    OnItemDataBound="rptFiles_ItemDataBound">
    <ItemTemplate>
    <asp:HyperLink ID="hplFile" runat="server" /> <br />
    </ItemTemplate>
    </asp:Repeater>
    </div>
    </form>
    </body>
    </html>


    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke

    <> wrote in message
    news:...
    > Hello,
    >
    > I would like to create dynamic hyperlinks in a web page when it is
    > first loaded by using ASP.NET. Basically there will be a list of
    > documents in a folder and I will list them all as a hyperlink for user
    > access.
    >
    > I wonder how I can go through the folder and create the dynamic
    > hyperlink on the fly in ASP.NET.
    >
    > Thanks in advance.
    >
     
    Teemu Keiski, Apr 21, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MasterNone
    Replies:
    0
    Views:
    2,208
    MasterNone
    Aug 16, 2006
  2. davetichenor
    Replies:
    1
    Views:
    908
    Eliyahu Goldin
    Oct 30, 2006
  3. MasterNone
    Replies:
    2
    Views:
    200
    JeffP@Work
    Sep 12, 2006
  4. Dave
    Replies:
    0
    Views:
    997
  5. Brian

    Fly outmenu on the fly

    Brian, Apr 8, 2005, in forum: Javascript
    Replies:
    0
    Views:
    127
    Brian
    Apr 8, 2005
Loading...

Share This Page