Avatar of M.L. Martin
M.L. MartinFlag 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
M.L. Martin
ASKER CERTIFIED SOLUTION
Avatar of M.L. Martin
M.L. Martin
Flag of United States of America image

Blurred text
THIS SOLUTION IS 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
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo