Avatar of Star79
Star79
Flag for United States of America asked on

Disable a Hyperlink in a gridview

Hello All,
How can I disable <asp:HyperLinkField control in a gridview based on a session["role"].
Thanks
.NET ProgrammingASP.NETC#

Avatar of undefined
Last Comment
Mlanda T

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Mlanda T

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Star79

ASKER
Hello,
Without converting into template column can we do this?
Thanks
Mlanda T

In the RowDataBound event above... you can just use this syntax:

dim myLink as HyperLink = e.Row.Cells(indexOfTheHyperLinkColumn).Controls(0)
if myLink isnot nothing then
     myLink.Enabled = (session["role"] = "Admin")
end if

NOTES:
indexOfTheHyperLinkColumn based on the position of the column in the gridview. First index is 0.
Please just check whether the HyperLink control is Controls(0) or otherwise Controls(1)... dont remember which is which
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck