M.L. Martin
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(ByV al sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView2.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If Not User.Identity.IsAuthentica ted Then
Dim h As HyperLink = DirectCast(e.Row.FindContr ol("HyperL ink1"), HyperLink)
Dim i As HyperLink = DirectCast(e.Row.FindContr ol("HyperL ink30"), HyperLink)
Dim j As HyperLink = DirectCast(e.Row.FindContr ol("HyperL ink2"), 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.
Protected Sub GridView2_RowDataBound(ByV
If e.Row.RowType = DataControlRowType.DataRow
If Not User.Identity.IsAuthentica
Dim h As HyperLink = DirectCast(e.Row.FindContr
Dim i As HyperLink = DirectCast(e.Row.FindContr
Dim j As HyperLink = DirectCast(e.Row.FindContr
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tried different syntax with intellisense until correct one was produced.
ASKER
Protected Sub DataList2_ItemDataBound(By
If e.Item.DataItem = DataControlRowType.DataRow
If Not User.Identity.IsAuthentica
Dim h As HyperLink = DirectCast(e.Item.FindCont
Dim i As HyperLink = DirectCast(e.Item.FindCont
Dim j As HyperLink = DirectCast(e.Item.FindCont
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'.