PDA

Click to See Complete Forum and Search --> : Find Control in a DataList..Easier Way?!


jesus4u
Jun 20th, 2003, 11:29 AM
Is there an easier way to take control of a control in a DataList without doing the FindControl method?


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

DevGrp
Jun 20th, 2003, 01:39 PM
No

Lethal
Jun 21st, 2003, 07:28 PM
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.