DataGrid Conditional Hyperlink

Posted on 2011-04-27
Last Modified: 2012-06-27
I have one form that I use to delete, edit, advanced edit, and restore.  I hide the columns based on the url variable value.  Since this form accesses several different folders, the hyperlink to the different files (e.g., images, documents) does not work.  I was wondering if I could conditionally add the DataTextFieldFormat and change it also based on the URL.

Maybe this is simpler than I am thinking, but I am not sure if this is an in page edit or a VB script edit.
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name" HeaderText="Name" />

Open in new window

Question by:atljarman
    LVL 9

    Expert Comment

    Dim HL1 As New HyperLink()
        HL1.Visible = True
        HL1.ID = "HL1"
        HL1.NavigateUrl = ""
        End If
        HL1.Text = "Yahoo"

    Author Comment

    This is a great suggestion.  I do use the name of the file in the row.  So for example

    Images:  HL1.NavigateURL = "images\{0}"
    Documents:  HL1.NavigateURL = "documents\{0}"
    Backups:  HL1.NavigateURL = "bkup\{0}"
    Pages:  HL1.NavigateURL = "{0}"

    I'm not sure if the Dim suggested will account for the row variable.  Also, do you then put this under the Page_Load sub?  
    LVL 7

    Expert Comment

    You've got this in a gridview?
    Put the hyperlink in a template field, and the values which will determine the style and text of your link in as datakeys for the gridview, then iterate through the rows on the databound event to amend each row's link accordingly

    Accepted Solution

    Thanks.  What I ended up doing was adding a separate column and hiding (.visible = false) the columns that did not apply to the page.
    LVL 53

    Expert Comment

    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now