Solved

Find a Control in a DataList

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

770 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