 |
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

March 5th, 2007, 02:54 PM
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
GridView Hyperlink
I have a gridView that get populated with files information using DirectoryInfo. Some of the columns returned are: name, FullName, Extention, Length, .....
I added a Hyperlink column and I want to be able to click on it on open the corresponding file (pdf).
The problem is that when I use DataNavigateUrlFields="fullname", the hyperlink is not active(not clickable). If I use DataNavigateUrlFields="name", the hyperlink is 'live' (clickable).
The only difference I can see between name and fullname is the size, as fullname returns the entire file path plus the file name.
Could anyone explain what's going on, or what I am doing wrong.
Thank you.
Here's is the hyperlink:
<asp:HyperLinkField Text="Download" DataNavigateUrlFormatString="~/downloadPDF.aspx?fullname={0}" HeaderText="Download" DataTextField="name" DataNavigateUrlFields="fullname" />
__________________
It\'s good to have skills. It\'s better to have imagination.
|

March 5th, 2007, 05:02 PM
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you Imar for answering...
On a page I have a text box. A user enters a'Part Number' and then clicks on a button. The idea is to parse the 'part number' entered and from there figure out where and what is the folder name that should display the files in it:
Hope the code is clear as I am testing it and there is a lot of uncommented text:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim partNumber As String '001-00235
Dim mainFolderName As String '001
Dim dashPosition As Integer
Dim rightSidePartNumber As String '00235
Dim subFolderName As String '002
Dim searchFolder As String
partnumber = Me.partNumberTextBox.Text
mainFolderName = Left(partNumber, 3)
dashPosition = InStr(partNumber, "-")
rightSidePartNumber = Right(partNumber, Len(partNumber) - dashPosition)
subFolderName = Left(rightSidePartNumber, 3)
If mainFolderName = "001" Or mainFolderName = "801" Then
searchFolder = mainFolderName & "-XXXXX\" & mainFolderName & "-" & subFolderName & "XX"
searchFolder = "C:\TEMP\pdf\" & searchFolder
End If
Try
Dim dirInfo As New DirectoryInfo(searchFolder)
'*************
'*************
If dirInfo.Exists Then
' dirinfo.GetFiles(partnumer & "*.pdf)
Me.GridView1.DataSource = dirInfo.GetFiles(partNumber & "*.pdf") '("*.*")
'Me.GridView1.DataSource = dirInfo.GetFiles("*.pdf")
Me.GridView1.DataBind()
Else : Me.partNumberTextBox.Text = "Directory does not exit: " & searchFolder 'MsgBox("Directory does not exit" & ": " & searchFolder)
'need to clear the grid
Dim dataTable As New Data.DataTable
Me.GridView1.DataSource = dataTable
Me.GridView1.DataBind()
Exit Sub
End If
Catch ex As Exception
Me.partNumberTextBox.Text = ex.Message ' MsgBox(ex.Message)
'need to clear the grid
Finally
End Try
End Sub
|

March 5th, 2007, 05:04 PM
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
GridView:
<asp:GridView ID="GridView1" runat="server" Font-Size="Smaller">
<Columns>
<asp:BoundField DataField="FullName" HeaderText="Path" />
<asp:BoundField DataField="Name" HeaderText="File Name" >
<ItemStyle Width="160px" />
</asp:BoundField>
<asp:HyperLinkField Text="Download" DataNavigateUrlFormatString="~/downloadPDF.aspx?fullname={0}" HeaderText="Download" DataTextField="name" DataNavigateUrlFields="name" />
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Bind("FullName","~/downloadPDF.aspx?") %>'>HyperLink</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
|

March 5th, 2007, 05:30 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Weird. I have seen things like this with a GridView and the fix was to set the HtmlEncode to False. However, that was with a BoundField, not an HyperLink or TemplateField.
Only way around this right now, without looking too much into this, is this:
<a href='<%# "SomeUrl.aspx?Path=" + Eval("FullName") %>' runat="server">Download</a>
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|

March 5th, 2007, 05:42 PM
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
yes it's weird, if i use extension , length, IsReadOnly, Exists it works.
does not work with :DirectoryName,LastAccessTimeUtc.
|

March 5th, 2007, 05:50 PM
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar how do i use :
<a href='<%# "SomeUrl.aspx?Path=" + Eval("FullName") %>' runat="server">Download</a>
should I replace the hyperlink column by that?
|

March 5th, 2007, 05:53 PM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Yes. Eval will pull the value of the column FullName from your datasource and place it in the above link.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
|

March 5th, 2007, 06:00 PM
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I added your line of code to the columns tag, like this:
*******************************
<asp:GridView ID="GridView1" runat="server" Font-Size="Smaller">
<Columns>
<asp:BoundField DataField="FullName" HeaderText="Path" />
<asp:BoundField DataField="Name" HeaderText="File Name" >
<ItemStyle Width="160px" />
</asp:BoundField>
<asp:HyperLinkField Text="Download" DataNavigateUrlFormatString="~/downloadPDF.aspx?fullname={0}" HeaderText="Download" DataTextField="name" DataNavigateUrlFields="Exists" />
<a id="A1" href='<%# ~/downloadPDF.aspx?fullname=" + Eval("FullName") %>' runat="server">Download</a>
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Bind("FullName","~/downloadPDF.aspx?") %>'>HyperLink</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
*******************************
but I get an error, saying the element 'a' cannot be nested within element 'columns'
|

March 5th, 2007, 07:13 PM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Is it an error or just a compiler warning (or message) as the latter will not cause your compilation to fail.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
|
|
 |