Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional hyperlink in a TemplateField

Status
Not open for further replies.

LarrySteele

Programmer
May 18, 2004
318
US
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:
[COLOR=red]if(ViewFlag=="Y") {[/color]
    <a class="hyperlink" onclick="submitRecord('<%# Eval("Fld1") %>','<%# Eval("Fld2") %>');"><%# Eval("Fld1") %></a>
[COLOR=red]}  else {[/color]
[COLOR=red]  <%# Eval("Fld1") %>*[/color]
[COLOR=red]}[/color]

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top