-
Oct 9th, 2008, 02:22 PM
#1
Thread Starter
Hyperactive Member
Open Word Document File from link on Datagridview
I have a database that hold some files, which can be Word, Excel or PDF files. I use a Datagridview to show these files and now I want to put a link on my gridview so that when the user clicks on the Hyperlink(?) button the file will open. So far I am not having any luck wiring it all up.
My select query looks like this
VB Code:
SELECT DocID
, DocumentName
, DocumentPath+DocumentName AS FilePath
FROM Documents
This gives me results like this
DocID: 1
DocumentName: Scanning range.doc
FilePath: C:\Docs\Scanning range.doc
My datagridview is showing all the fields correctly and all I need to do is to add the Hyperlink field to do the download but no matter how I try it I am not able to get it to work.
VB Code:
<Columns>
<asp:HyperLinkField
DataNavigateUrlFields="FilePath"
DataNavigateUrlFormatString="DocID={0}"
Text="Open"
HeaderText="Document" />
</Columns>
What am I doing wrong?
-
Oct 9th, 2008, 02:43 PM
#2
Frenzied Member
Re: Open Word Document File from link on Datagridview
what is happening when you click the link?
-
Oct 9th, 2008, 02:59 PM
#3
Thread Starter
Hyperactive Member
Re: Open Word Document File from link on Datagridview
Well I never make it to the link. The designer fails with this error Error Creating Control - dgvDocumentsDatabinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.HyperLinkField does not have a DataBinding event.
I have tried the link a couple of different ways and got variations on the error but they all say basically the same thing.
-
Oct 9th, 2008, 03:33 PM
#4
Thread Starter
Hyperactive Member
Re: Open Word Document File from link on Datagridview
Ok I finally got past the error and the page opens now with this.
vb Code:
<asp:HyperLinkField
DataTextField="FilePath"
DataNavigateUrlFields="DocID"
DataNavigateUrlFormatString="{0}" />
When I hover over the link I am getting the DocID now. So I think I am on the right track but I just can't get it to work all the way.
-
Oct 9th, 2008, 03:56 PM
#5
Thread Starter
Hyperactive Member
Re: Open Word Document File from link on Datagridview
I am close now
vb Code:
<asp:HyperLinkField
HeaderText="Action"
DataTextField="DocID"
DataNavigateUrlFields="DocumentName"
DataNavigateUrlFormatString="{0}" />
This is looking for the file at the root level and I need to go one directory down to a sub directory. Can I use a Server Map Path with this?
-
Oct 9th, 2008, 04:00 PM
#6
Thread Starter
Hyperactive Member
Re: Open Word Document File from link on Datagridview
A ha! DataNavigateUrlFormatString="/documents/{0}" />
-
Oct 10th, 2008, 01:40 AM
#7
Hyperactive Member
Re: Open Word Document File from link on Datagridview
if it is asp.net
directly u can use window.open(//Word file path)
MCP, MCTS, Microsoft MVP [Asp.Net/IIS]
For more .NET development tips visit .NET Tips
If the post is useful then please Rate it
-
Oct 11th, 2008, 03:24 AM
#8
Re: Open Word Document File from link on Datagridview
Assuming the DOC files are on the server, in C:\docs\etc then the user won't be able to see it at all. You'll need to link them to a handler page which in turn does a Response.WriteFile() from the local server location so that the user gets the save/open/cancel dialog prompt.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|