Solved

Find a Control in a DataList

Posted on 2013-11-30
3
429 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

809 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