I would rather suggest to use
FindControl()
with a bit of defensive programming, in the
ItemDataBound
event of
DataList
:
if (e.Item.ItemType == ListItemType.Header)
{
TextBox txtEmp = e.Item.FindControl("TextBox1") as TextBox;
if (txtEmp != null)
{
String empnam = txtEmp.Text;
}
}