Link to home
Start Free TrialLog in
Avatar of Star79
Star79Flag 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
ASKER CERTIFIED SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Star79

ASKER

Hello,
Without converting into template column can we do this?
Thanks
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