Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends

i am getting an error of

Object reference not set to an instance of an object.

I am using this code

C#
var tv = sender as TreeView;
var dataListItem = tv.NamingContainer as DataListItem;
Panel pnl1 = (Panel)dataListItem.FindControl("pnlComments");


Kindly Help
Posted
Updated 5-May-12 0:13am
v2

1 solution

The reason may be that tv.NamingContainer is null.
Put a break point on the line
C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900