Solved

Find a Control in a DataList

Posted on 2013-11-30
3
425 Views
Last Modified: 2013-12-01
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.
0
Comment
Question by:derrekdeveloper
  • 3
3 Comments
 

Author Comment

by:derrekdeveloper
ID: 39688357
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'.
0
 

Accepted Solution

by:
derrekdeveloper earned 0 total points
ID: 39688426
Protected Sub DataList2_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs) Handles DataList2.ItemDataBound

        If e.Item.ItemType = ListItemType.Item 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)
0
 

Author Closing Comment

by:derrekdeveloper
ID: 39688427
Tried different syntax with intellisense until correct one was produced.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now