Ya, you need to check for the Item || ItemType, since ItemCreated fires for
the headeritem and footeritem and the other templates, and you won't find
your control in there.
simply do:
e.Item.FindControl("lblTest");
e is the 2nd argument, e.Item is the DataListItem (which you can *think* of
as the actual row being bound)...within this row is the control you want to
find.
you CAN do it like DataList1.FindControl("XXX").FindControl("myContro l");
but DataList1.FindControl("XXXX") just returns the same control as e.Item.
Karl
--
http://www.openmymind.net/ http://www.codebetter.com/
<ne***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>I have this code:
protected void DataList1_ItemCreated(object sender,
DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Label lbl = (Label)DataList1.FindControl("lblTest");
Response.Write(lbl.Text);
}
}
First, do I have to have that ListItemType.item, etc. stuff in asp.net
2.0? On the findcontrol, I did some searching and saw where I had to
have a something like
DataList1.FindControl(myID).FindControl("myControl ");
I don't know what the myID is or if I need it.
Thank you for any help.