Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 5th, 2007, 02:54 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
  #2 (permalink)  
Old March 5th, 2007, 04:38 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

How does the rest of your code look like?

Can you post a fully reproducible scenario?

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.
  #3 (permalink)  
Old March 5th, 2007, 05:02 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


  #4 (permalink)  
Old March 5th, 2007, 05:04 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>

  #5 (permalink)  
Old March 5th, 2007, 05:30 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
  #6 (permalink)  
Old March 5th, 2007, 05:42 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes it's weird, if i use extension , length, IsReadOnly, Exists it works.
does not work with :DirectoryName,LastAccessTimeUtc.

  #7 (permalink)  
Old March 5th, 2007, 05:50 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar how do i use :
<a href='<%# "SomeUrl.aspx?Path=" + Eval("FullName") %>' runat="server">Download</a>
should I replace the hyperlink column by that?


  #8 (permalink)  
Old March 5th, 2007, 05:53 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
================================================== =========
  #9 (permalink)  
Old March 5th, 2007, 06:00 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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'

  #10 (permalink)  
Old March 5th, 2007, 07:13 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
================================================== =========
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening a text file using hyperlink in a gridview absu General .NET 1 March 6th, 2009 02:03 AM
HyperLink in a gridview contro to open word docmen Otoniel ASP.NET Espanol 0 October 7th, 2008 01:11 AM
Get GridView Cell Value Based on GridView Column stublair C# 2008 aka C# 3.0 0 September 4th, 2008 08:30 AM
Using Hyperlink field in GridView asp_convert ASP.NET 2.0 Basics 2 February 7th, 2007 07:33 PM
hyperlink pab006 Classic ASP Basics 5 December 17th, 2003 10:33 AM



All times are GMT -4. The time now is 05:41 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.