To bind radtreeview with database first get all the parents data items and bind that items to rad tree
after that get child data of that parents items and then bind that data with rat tree view on NodeExpand event and so on.
Code Snippet
- protected void Page_Load(object sender, EventArgs e)
- {
-
- if (!IsPostBack)
- {
-
- RadTreeNode parentNode = new RadTreeNode("Parent", "-1");
- parentNode.Font.Size = 14;
- parentNode.Font.Bold = true;
- parentNode.ForeColor = Color.SaddleBrown;
- parentNode.Expanded = true;
- parentNode.ImageUrl = "../Images/abc.png";
- parentNode.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
- parentNode.AllowEdit = false;
- RadTreeView1.Nodes.Add(parentNode);
- }
- }
-
- protected void RadTreeView1_NodeExpand(object sender, RadTreeNodeEventArgs e)
- {
-
- var result = e.Node.Value;
- var category = e.Node.Category;
- if( e.Node.Category=="Parents")
- {
- var childNodes = getChildDataBByParentId(int.Parse(result));
- if childNodes > 0)
- {
- foreach (var child in childNodes )
- {
- RadTreeNode cA = new RadTreeNode();
- cA.Font.Bold = true;
- cA.Value = child.childID.ToString();
- cA.ImageUrl = "../Images/Person.png";
- cA.Text = child.childName;
- cA.AllowEdit = false;
- cA.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
- cA.Category = "child";
- parentNode.Nodes.Add(cA);
-
-
- }
- }
- }
- if( e.Node.Category=="child")
- {
-
- var subChildNodes = getSubChildData(int.Parse(result));
- if subChildNodes > 0)
- {
- foreach (var subChild in subChildNodes )
- {
- RadTreeNode sA = new RadTreeNode();
- sA.Font.Bold = true;
- sA.Value = child.childID.ToString();
- sA.ImageUrl = "../Images/Person.png";
- sA.Text = child.childName;
- sA.AllowEdit = false;
- sA.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
- sA.Category = "child";
- cA.Nodes.Add(sA);
-
-
- }
- }
- }
-
-
- }
c8efb101-01b2-41c0-822f-de122fa46c36|0|.0
Categories:
ASP.NET, Telerik
8. January 2012
Tags:
RadTreeView