The reason may be that
tv.NamingContainer
is
null
.
Put a
break point
on the line
Panel pnl1 = (Panel)dataListItem.FindControl("pnlComments");
run the program and when the execution stops at the break point, check whether
tv.NamingContainer
is
null
. If so take check that code to get non null value.