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

Top 5 Contributors of the Month
Easy Web
Imran Ghani

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");
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();
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();
FillChild(child, child .Value );

return 0;
return 0;

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.


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

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