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