Results 1 to 3 of 3

Thread: Find Control in a DataList..Easier Way?!

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Find Control in a DataList..Easier Way?!

    Is there an easier way to take control of a control in a DataList without doing the FindControl method?

    Code:
            Dim myDataListItem As DataListItem
            For Each myDataListItem In DataList1.Items
                If TypeOf myDataListItem Is Label Then
                    Dim lblText As Label = myDataListItem.FindControl("lblText")
                    lblText.Style.Item("left") = 0
                    Dim lblTitle As Label = myDataListItem.FindControl("lblTitle")
                    lblTitle.Style.Item("left") = 0
                Else
                    Dim imgMain As Object = myDataListItem.FindControl("imgMain")
                    imgMain.Visible = False
                End If
    
            Next

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    No

  3. #3
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Yes.

    Add a protected member to your code-behind with the same type and name as your control your wanting to work with. Make sure the control has its id property set and the runat attribute set to server.
    Last edited by Lethal; Jun 23rd, 2003 at 10:28 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width