In the below function I have a DataTable which resets during recursion of the function. How can I solve this problem?
I have to create table once and add rows repeatedly in each repeat of the function.
Please help!
private DataTable GetSelectedTreeNodes(TreeNode parentTreeNode)
{
DataTable tvp = new DataTable();
tvp.Columns.Add(new DataColumn("Suburb"));
if (parentTreeNode.Checked)
{
ListBox1.Items.Add(parentTreeNode.Text);
tvp.Rows.Add(parentTreeNode.Text);
tvp.Rows.Add(parentTreeNode.Text);
}
if (parentTreeNode.ChildNodes.Count > 0)
{
foreach (TreeNode childTreeNode in parentTreeNode.ChildNodes)
{
GetSelectedTreeNodes(childTreeNode);
}
}
return tvp;
}
Prakash MalakarPosted Apr 23, 2015, 5:49 AM
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Syed ShanuPosted Apr 23, 2015, 4:29 AM
If is this is Web application then
DataTable tvp;
publiv void Page_Load
{
if(!page.ispostback)
{
tvp = new DataTable();
tvp.Columns.Add(new DataColumn("Suburb"));
}
}
//here your method