I'm using the <asp:gridview control and I have a boundfield that shows the path to a document. How can I make this a hyperlink so that the document can be opened by the user?
Now my Path appears as a hyperlink, but when I click on the hyperlink nothing happens.
I have one file that is a full path in the form "C:\temp\MyDoc.doc" clicking the link does nothing.
Other's are in my temp path and show as "\temp\1234.htm" for example. Here it is trying to go to http://localhost:3209/temp/1234.htm" and I receive resource cannot be found error
billcrawley
Member
341 Points
286 Posts
Making a hyperlink in GridView
Nov 23, 2012 02:53 PM|LINK
Hi All,
I'm using the <asp:gridview control and I have a boundfield that shows the path to a document. How can I make this a hyperlink so that the document can be opened by the user?
thanks
oned_gk
All-Star
31798 Points
6499 Posts
Re: Making a hyperlink in GridView
Nov 23, 2012 03:29 PM|LINK
oned_gk
All-Star
31798 Points
6499 Posts
Re: Making a hyperlink in GridView
Nov 23, 2012 03:31 PM|LINK
anil.india
Contributor
2613 Points
453 Posts
Re: Making a hyperlink in GridView
Nov 23, 2012 03:35 PM|LINK
You can use ItemTemplate to put hyperlink control, and write code behind code to download the file onClick event of this.
If you want to persist with use of BoundField, you can refer this simple example -
http://csharpdotnetfreak.blogspot.com/2012/06/download-files-gridview-linkbutton.html
codepattern.net/blog ||@AnilAwadh
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Making a hyperlink in GridView
Nov 24, 2012 04:06 AM|LINK
Hi,
Try <asp:HyperLink> by setting NavigateUrl and Text properties,please have a look at this:
[aspx]
[cs]
billcrawley
Member
341 Points
286 Posts
Re: Making a hyperlink in GridView
Nov 26, 2012 07:58 AM|LINK
HI All,
I have changed my bound field to:
<asp:TemplateField HeaderText="Path" SortExpression="File"> <ItemTemplate> <asp:HyperLink NavigateUrl='<%#Eval("File") %>' Text='<%#Eval("File")%>' runat="server" Target="_blank"></asp:HyperLink> </ItemTemplate> </asp:TemplateField>Now my Path appears as a hyperlink, but when I click on the hyperlink nothing happens.
I have one file that is a full path in the form "C:\temp\MyDoc.doc" clicking the link does nothing.
Other's are in my temp path and show as "\temp\1234.htm" for example. Here it is trying to go to http://localhost:3209/temp/1234.htm" and I receive resource cannot be found error
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Making a hyperlink in GridView
Nov 26, 2012 08:05 AM|LINK
No, you cannot do to write down your absolute path, others who accessing the website cannot access the file through your local file web path.
Hi again,
Your "Name" property something like this should contain:
/Temp/xxxx.htm
And there should be a folder called "Temp" under the root of your proj, with the specific file there.
sarathi125
Star
13599 Points
2691 Posts
Re: Making a hyperlink in GridView
Nov 26, 2012 08:11 AM|LINK
Hi,
You may use this approach
CodeBehind
protected void Page_Load(object sender, EventArgs e) { dynamic dirInfo = new DirectoryInfo(Server.MapPath("~/YourFolder")); if (dirInfo.Exists) { GridView1.DataSource = dirInfo.GetFiles(); GridView1.DataBind(); } }The gridView
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets