C# Tutorials and offshore development in India

Tutorials Resources Forum Reviews Interview Jobs Projects Training Your Ad Here


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...




Resources » Articles » ASP.NET/Web Applications »

Get a populate on demand treeview in asp.net 2.0


Posted Date: 11 Sep 2008    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: Gitolekha RayMember Level: Gold    
Rating: 1 out of 5Points: 15



Populate on demand treeview can be very fast compared to a treeview which is loaded altogether.When we click the parent node of the treeview only it's childnodes are populated, so we populate the treeview based on demand(parent node).
The TreenodePopulate event is called whenever a node is clicked to expand.
Do not forget to mention PopulateOnDemand as true.
EnableClientScript is used to specify whether client-side validation is enabled. This will stop the post backs to the server.

 
public System.Web.UI.WebControls.TreeView tvCountry = new System.Web.UI.WebControls.TreeView();
string strCountry =”Country”;
tvCountry.ID =”tvCountry”;
tvCountry.EnableClientScript = true;
//gets called whenever a node is clicked to expand.
tvCountry.TreeNodePopulate += new TreeNodeEventHandler
(tvCountry_TreeNodePopulate);
TreeNode n2 = new TreeNode(strCountry, strCountry);
n2.Expanded = false;
n2.SelectAction = TreeNodeSelectAction.None;
n2.PopulateOnDemand = true;
n2.ShowCheckBox = false;



/* Implement logic for populating the treeview, here I have given a small test case to elaborate the functionality */


void tvGeoScope_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
string[] personNames = GetPersonNames(e.Node.Value);

foreach (string personName in personNames)
{
TreeNode nn = new TreeNode(personName, personName);
nn.Expanded = false;

nn.PopulateOnDemand = true;
nn.ShowCheckBox = true;

e.Node.ChildNodes.Add(nn);
}
}

public string[] GetPersonNames(string personType)
{
List persons = new List();

switch (personType)
{
case "Country":
persons.Add("Europe");
persons.Add("Melanesia");
break;

case "Europe":
persons.Add("Austria");
persons.Add("Begium");
break;

case "Melanesia":
persons.Add("Fiji");
persons.Add("Solomon Islands");
break;
}

return persons.ToArray();
}





Responses to the resource: "Get a populate on demand treeview in asp.net 2.0"

No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
PopulateOnDemand  .  TreeView  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Problem with implementing tab control using AJAX in user control
Previous Resource: How to Search xml document
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
More Resources




About Us    Contact Us    Privacy Policy    Terms Of Use