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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid hyperlink file

Status
Not open for further replies.

hamking01

Programmer
Joined
May 30, 2004
Messages
238
Location
US
I currently have a datagrid where a free form columnC lists the filenames stored on the server. Below the datagrid there are links to each file where it will open up for users to downlad. The free form column filenames are created by databinding from ColumnA and ColumnB:

ColumnA ColumnB ColumnC(textbox freeform)
1 A 1_A.pdf
2 B 2_B.pdf

Below datagrid users click on links
<a href="1_A.pdf>1_A.pdf</a>
...

It's becoming a hassle to look through the list to find the file to open, as the list is getting very long. Is it possible to add a hyperlink column to a datagrid where the link will open pdf files saved on the server. For example:

ColumnA ColumnB ColumnC(hyperlink)
1 A 1_A.pdf
2 B 2_B.pdf

So if I clicked on a link in 1_A.pdf it will open up the files directly. I've tried modifiying the DataNavigateUrlFormatString by binding data for ColumnA and ColumnB but it always directs to a url page.
Is what i'm trying to do possible in a datagrid. Any help would be appreciated.

 
Yes, it's possible, what does your attempted code look like so that someone here can have a jump start on your field names, and basic methodology?

-p

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
For the data grid, the last column I have as follows:

<asp:TemplateColumn HeaderText="Filename"
Visible="True">
<ItemTemplate><%# DescrSearch.FieldValue("Descr", Container) %>_<%# DescrSearch.FieldValue("Version", Container) %>_<%# DescrSearch.FieldValue("Test_no", Container) %>.pdf</ItemTemplate>
</asp:TemplateColumn>

A free form that creates filenames in the following format:
"Descr"_"Version"_"Test_no".pdf

I've tried changing it to a hyperlink column where

DataNavigateUrlFormatString=<%# DescrSearch.FieldValue("Descr", Container) %>_<%# DescrSearch.FieldValue("Version", Container) %>_<%# DescrSearch.FieldValue("Test_no", Container) %>.pdf

This causes the following error:
Parser Error Message: Literal content ('<asp:HyperLinkColumn HeaderText="test" Visible="True" DataTextField="Descr" DataNavigateUrlField="Descr" DataNavigateUrlFormatString="') is not allowed within a 'System.Web.UI.WebControls.DataGridColumnCollection'.

I've also tried the following:
<asp:HyperLinkColumn
HeaderText="Download"
Visible="True"
DataTextField="Descr"
DataNavigateUrlField="Descr"
DataNavigateUrlFormatString="?Descr={0}?Version={0}Test_no{0}.pdf"/>
</Columns>

But since I don't have a actual url in the DataNavigateUrlFormatString it directs back to track.aspx (the page all this code on)with all three parameters being from Descr={0}. I'm sure I have to add "Version" and "Test_no" to the DataTextfield but I'm totally lost how to do this.

I'm pretty new to this and am just learning this stuff through trial and error. Any help in the right direction is appreciated.
 
DataNavigateUrlFormatString=<%# DescrSearch.FieldValue("Descr", Container) %>_<%# DescrSearch.FieldValue("Version", Container) %>_<%# DescrSearch.FieldValue("Test_no", Container) %>.pdf

is your attack plan, but you must surround the content with single ticks -- '

so:

DataNavigateUrlFormatString='<%# DescrSearch.FieldValue("Descr", Container) %>_<%# DescrSearch.FieldValue("Version", Container) %>_<%# DescrSearch.FieldValue("Test_no", Container) %>.pdf'

-p

Something along these lines. The missing ticks are causing that exception.

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Putting the single quotes causes the url to include everything within the single quotes to become the link. It doesn't convert the tags to their values. Providing

DataNavigateUrlFormatString='<%# DescrSearch.FieldValue("Descr", Container) %>_<%# DescrSearch.FieldValue("Version", Container) %>_<%# DescrSearch.FieldValue("Test_no", Container) %>.pdf'

Caused the URL to become:


I've also tried " in place of ' but error comes up as:
Literal content ('<asp:HyperLinkColumn HeaderText="Download" Visible="True" DataTextField="Descr" DataNavigateUrlField="Descr" DataNavigateUrlFormatString="') is not allowed within a 'System.Web.UI.WebControls.DataGridColumnCollection'.
 
Try something like this:

<a href='<%# DescrSearch.FieldValue("Descr", Container) & "_" & DescrSearch.FieldValue("Version", Container) & "_" & DescrSearch.FieldValue("Test_no", Container) & ".pdf" %>'>
Click here for your pdf
</a>

-p

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Got it to work as follows:

<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink runat="server" Text="tetst"
NavigateUrl='<%# DescrSearch.FieldValue("Descr", Container) & "_" & DescrSearch.FieldValue("Version", Container) & "_" & DescrSearch.FieldValue("Test_no", Container) & "_" & DescrSearch.FieldValue("Pass_Fail", Container) & ".pdf" %>' />
</ItemTemplate>
</asp:TemplateColumn>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top