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

Hide <asp:HyperLink if user not logged within Gridview

The following code helped me hide asp hyperlinks if user is not logged in. I do not code very very if at all. My problem is I need to do the same thing within a GridView Control. I don't know the syntax well enough or the arguments to modify the code. Could someone help me changed the code to perform the same functionality with with a GridView:

Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs) Handles ListView1.ItemDataBound
        If e.Item.ItemType = ListViewItemType.DataItem Then
            If Not User.Identity.IsAuthenticated Then
                Dim h As HyperLink = DirectCast(e.Item.FindControl("HyperLink1"), HyperLink)
                Dim i As HyperLink = DirectCast(e.Item.FindControl("HyperLink30"), HyperLink)
                Dim j As HyperLink = DirectCast(e.Item.FindControl("HyperLink2"), HyperLink)
                If h IsNot Nothing Then
                    h.Visible = False
                End If
                If i IsNot Nothing Then
                    i.Visible = False
                End If
                If j IsNot Nothing Then
                    j.Visible = False
                End If
            End If
        End If
    End Sub

I made an attempt to modify the code but I am not sure if the syntax will even work. It definitely won't compile:
-------------------------------------------------------------My failed attempt below
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If Not User.Identity.IsAuthenticated Then
                Dim h As HyperLink = DirectCast(DataControlRowType.DataRow("HyperLink1"), HyperLink)
                Dim i As HyperLink = DirectCast(e.Item.FindControl("HyperLink30"), HyperLink)
                Dim j As HyperLink = DirectCast(e.Item.FindControl("HyperLink2"), HyperLink)
                If h IsNot Nothing Then
                    h.Visible = False
                End If
                If i IsNot Nothing Then
                    i.Visible = False
                End If
                If j IsNot Nothing Then
                    j.Visible = False
                End If
            End If
        End If
    End Sub
ASP.NET

Avatar of undefined
Last Comment
derrekdeveloper

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
derrekdeveloper

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61