Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Find a Control in a DataList

Posted on 2013-11-30
3
Medium Priority
?
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

I have a large data set and a SSIS package. How can I load this file in multi threading?
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

610 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