473,408 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Add dynamic hyperlink on the fly in ASP.NET

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 '06 #1
1 2610
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

<sw**********@yahoo.com> wrote in message
news:11*********************@t31g2000cwb.googlegro ups.com...
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 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rob Rogers | last post by:
I am old programmer, but this asp.net stuff throws me for a loop. I have an asp.net page that I need to create a dynamic hyperlink from based on the user selection from the drop down list and...
2
by: Dave Williamson | last post by:
When a ASPX page is created with dynamic controls based on what the user is doing the programmer must recreate the dynamic controls again on PostBack in the Page_Load so that it's events are wired...
1
by: Gerald Baeck | last post by:
I want to realize a dynamic hyperlink, which changes onclick it's text and it's navigateurl. Unfortunately there is no event for a hyperlink like onclick for buttons. Is there another way to...
2
by: Jason | last post by:
I have a data grid with a hyperlink column. The hyperlink is created by a class that extracts the link from an XML Document. How can I populate the hyperlink column in the data grid with the...
4
by: EvelynAnd Ethan | last post by:
Hi, ItemCommand event not firing from a dynamic user control ,WHERE A DATAGRID HAS BUTTON,when i click on the linkbutton first time the itemcommand event doesnt fire,second time event fires up ...
3
by: sloesch | last post by:
I am working with VS.net 2003, framework 1.1, developing with VB.net, and ASP.net, and I would like to know how you can create a dynamic hyperlink on the fly to a document stored in a SQL database?...
2
by: Dominique | last post by:
Is it possible to change the size of a Dynamic Panel and fix it? Thanks, -- Dominique
1
by: mitramay | last post by:
I am creating a dynamic datagrid. The controls in some of the template columns will have to be generated based on the data contained in them (i.e. the data for that respective DataField column)....
1
by: Carlos | last post by:
Hi all, I need to create a set of dynamic hyperlinks in a page. I got: PlaceHolder mainpanel = new PlaceHolder(); foreach (DataRow row in events_table.Rows) {
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.