Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I posted a query a short while ago and had an informed answer within a couple of hours. Terrific!..."

Geography

Where in the world do Tek-Tips members come from?

Conditional hyperlink in a TemplateField

LarrySteele (Programmer)
15 Jun 12 11:32
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:

CODE

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

CODE

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,
Larry
LarrySteele (Programmer)
15 Jun 12 11:54
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.

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!

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