It depends on where in the page life-cycle you are. The DataList uses ASP.NET templates to build it's internal control collection, this doesn't happen until you've called DataBind
, which normally happens automatically just before PreRender
. And you can't find controls in the control collection until they have been created.
Where in the page life-cycle are you doing this? What's the context? There's other things to which can further complicate this (one thing is that FindControl is not recursive) in that it will not necessarily search down through each and every naming container. But I'd like to know more about in what context this doesn't work, becuase it does, but you need to be careful.
EDIT:
Something like this should do the trick:
<asp:DataList runat="server" ID="DataList1" OnPreRender="DataList1_PreRender">...</asp:DataList>
And then code behind:
protected void DataList1_PreRender(object sender, EventArgs e)
{
// the sender in this case is the DataList1 control
// i often prefer to rely on the sender argument
Label label1 = (Label)((Control)sender).FindControl("Label1");
label1.Text = "Yay, it looks like this works!";
}