Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display file path hyperlink in gridview

Status
Not open for further replies.

stonehead

Technical User
May 2, 2007
58
US
Hi all,

I use gridview to display data from a table. In one field I have a .pdf file path. I just don't know how to make it shown in hyperlink. Any help is greatly appreciated.
(in SQL table that field has the value of C:\temp\filename.pdf)
in asp.net page my code looks like this

<asp:GridView ID="gvViewStatus" runat="server" BackColor="White"
BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"
DataSourceID="SqlDataSource1" AutoGenerateColumns="False" >
<RowStyle BackColor="White" ForeColor="#330099" />
<Columns>
<asp:BoundField DataField="doc_path" HeaderText=".pdf file path" SortExpression="doc_path" >
<FooterStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:CommandField ShowEditButton="True" />
</Columns>

Thank you,
 
First problem, you are using datasource controls. Don't. They are problematic.

Second, you want to dispaly "C:\temp\filename.pdf" as a hyperlink correct?
If so, why, the client won't be able to access a file that way.
 
use a template field with a hyperlink. set the url to the file path. something like
Code:
<asp:templatecolumn headertext=".pdf">
  <itemtemplate>
    <asp:hyperlink navigateurl='<%#Eval("url field")%>' text="view" runat="server" id="link"/>
  </itemtemplate>
</asp:templatecolumn>

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Thanks for all your helps. In the example I gave C:\ without thinking. It's gonna be a network drive not my local C drive. Sorry for the confusion. I'm not very familiar with .NET. I don't do coding very often. The tutorials video my company bought use all data source, so I guess that the only way I know how to do so far. I'm still learning here.
 
Question for jeeckley,

I did as you said. When I hover the link text the url appears as file:///c:/temp but nothing opens. Do I miss anything ? And since this is a editable field, how should I fix the code in EditItemTemplate. Much appreciated.

<asp:TemplateField HeaderText=".pdf file path" SortExpression="doc_path">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("doc_path") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:hyperlink navigateurl='<%#Eval("doc_path")%>' text="open.pdf file" runat="server" id="link"/>
</ItemTemplate>
<FooterStyle HorizontalAlign="Left" />
</asp:TemplateField>
 
yes, you are pointing to a file, not a url, so it's formatted that way.

i don't understand your edit question. if it's editable allow the user to edit it, if not, display the value is a label or some other non-editable control.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
It's for user to edit it. Thank you.
For the file path. It works. It was my false.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top