Link to home
Start Free TrialLog in
Avatar of M.L. Martin
M.L. MartinFlag for United States of America

asked on

Find a Control in a DataList

I need to know how to find a hyperlink control in a datalist in my code behind. The following code works great with a GridView:

   Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView2.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If Not User.Identity.IsAuthenticated Then
                Dim h As HyperLink = DirectCast(e.Row.FindControl("HyperLink1"), HyperLink)
                Dim i As HyperLink = DirectCast(e.Row.FindControl("HyperLink30"), HyperLink)
                Dim j As HyperLink = DirectCast(e.Row.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

Can someone convert this code for me in a DataList. Or please respond with what the code would be in a DataList.
Avatar of M.L. Martin
M.L. Martin
Flag of United States of America image

ASKER

This is what I have come up with so far:

Protected Sub DataList2_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs) Handles DataList2.ItemDataBound

        If e.Item.DataItem = DataControlRowType.DataRow 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

But I receive this error:

Operator '=' is not defined for type 'DataRowView' and type 'DataControlRowType'.
ASKER CERTIFIED SOLUTION
Avatar of M.L. Martin
M.L. Martin
Flag of United States of America 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
Tried different syntax with intellisense until correct one was produced.