.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to Exit From Recursion loop

Posted By: Vasu Hajare     Posted Date: March 09, 2011    Points:5   Category :ASP.Net
Hello Below I have given code .I want exit after all loop from my recursion . I am not understanding Where to give...

public void load_tree()
{
DataSet PrSet = PDataset("Select * from categories where idparentcategory =1");
TreeView1.Nodes.Clear();
foreach (DataRow dr in PrSet .Tables [0].Rows)
{
if ((int)dr["idparentcategory"] == 1)
{
TreeNode tnParent = new TreeNode();
tnParent.Text = dr["categoryDesc"].ToString().Trim();
tnParent.Value = dr["idCategory"].ToString().Trim();
tnParent.Expand();
TreeView1.Nodes.Add(tnParent);
FillChild(tnParent, tnParent.Value);

}
}
}
public int FillChild(TreeNode parent, string idCategory)
{

DataSet ds = PDataset("Select * from categories where idparentcategory =" + idCategory);
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
TreeNode child = new TreeNode();
child.Text = dr["categoryDesc"].ToString().Trim();
// string temp = dr["idCatagory"].ToString();
child.Value = dr["idCategory"].ToString();
child.Collapse();
parent.ChildNodes.Add(child);
FillChild(child, child .Value );

}
return 0;
}
else
{
return 0;
}
}


Responses
Author: Dhiraj Ranka             
Posted Date: March 09, 2011     Points: 20   

You can follow this blog, it is exactly the same what you are doing, only you are taking data from database and in my blog I am taking data from generic list.

http://www.dhirajranka.com/?p=308

Hope this helps

Hope this helps.

Thanks & Regards,
Dhiraj Ranka
http://www.twitter.com/dhirajranka | http://www.dhirajranka.com


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend