Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Conditional hyperlink in a TemplateField

Conditional hyperlink in a TemplateField

Conditional hyperlink in a TemplateField

I'm working on my first ASP.Net site - after many years with ColdFusion - and hit a minor challenge, but not sure how to find the solution.

I have a GridView. I've defined a TemplateField on the first column so I can have a link from said column:


<a class="hyperlink" onclick="submitRecord('<%# Eval("Fld1") %>','<%# Eval("Fld2") %>');"><%# Eval("Fld1") %></a>

The GridView is a list of employees matching some search criteria. We're going to restrict user access based on their roles.

Original approach was to filter the list results. In other words, if you're only authorized to view US employees, then we'd filter the search list to US employees only.

We're not going to filter the list this way. The reason: this is confusing to the user. If they know an employee is in the system, but they can't see the record in the search list, their presumption is that the app is broken. Got it.

What I want to do is this: show all employees that meet the search criteria. For those that the user is allowed to view, we keep this hyperlink. For the remaining, we'll display the value plus an indicator (* or [R] come to mind), and we'll display text only, with no hyperlink.

So in pseudo code, I'm visioning something like this:


if(ViewFlag=="Y") {
<a class="hyperlink" onclick="submitRecord('<%# Eval("Fld1") %>','<%# Eval("Fld2") %>');"><%# Eval("Fld1") %></a>
} else {
<%# Eval("Fld1") %>*

It's the lines in red that have me scratching my head. ViewFlag would be a column from my query and it's pretty straight forward.

Sorry if this is an easy question - but I wasn't able to figure out the right question to ask Google.

Thanks for any suggestions,

RE: Conditional hyperlink in a TemplateField

Once again... Not 20 minutes after I post, I found the answer: http://www.stonecoastwebdesign.com/blog/2008/01/27....

Funny thing - I stumbled upon the magic words when trying to create the title for this thread. Conditional was the word I needed for my search.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close