ASP. NET third-party UI control Telerik usage records for the TreeVIew of Kendoui

Source: Internet
Author: User

First, the front desk display

Note: Remove all nodes at once

functionLoadtreedata () {$.ajax ({type:' POST ', URL:' @ (html.urlhref ("Scriptsite", "/filesmanager/myfiles/getfoldertree")) ', data: {}, Success:function(Result) {if(Result) {Inlinedefault=NewKendo.data.HierarchicalDataSource ({data:eval (Result), schema: {model: {children:"Items"                                }                            }                        }); $("#treeviewFolder"). Kendotreeview ({datasource:inlinedefault, CHANGE:ONTREEVIEWC hange, DataTextField: ["Text"]                        }); }                Else{}}, Error:function(Err) {Window.alert (err); }        });}

Second, the backstage implementation

1. Get the main method of the tree

         Public string Getfoldertree ()        {            Listnew  filemanagelogic (). Getmyfoldertree (currentuser.id);             string strresult = Newtonsoft.Json.JsonConvert.SerializeObject (lstnodes);             return strresult;        }

Get all the data you need in a tree control based on conditions

         PublicList<cust_treeviewitemmodel>Getmyfoldertree (Guid userId) {List<Cust_TreeViewItemModel> Lstresult =NewList<cust_treeviewitemmodel>(); Dvacontext Context=NewDvacontext (); List<es_data_path_mini> lstpaths = context. Database.sqlquery<es_data_path_mini> ("Select Id,pid,seq,d_path from Es_data_path where createuserid= '"+ userid.tostring () +"'").            ToList ();            Getkendotree (lstpaths, Lstresult, context, userId); returnLstresult; }

Recursive implementation of parent-child binding relationships

Private voidAddchildkendotree (list<cust_treeviewitemmodel> lsttree, Es_data_path_mini CurrentPath, List<es_data_path_ Mini> Lstpaths,BOOLisfirstlevel) {Cust_treeviewitemmodel Currenttreenode=NewCust_treeviewitemmodel (); Currenttreenode.text=Currentpath.d_path; Currenttreenode.id=currentPath.ID.ToString (); Currenttreenode.items=NULL; Currenttreenode.parentid=currentPath.PID.ToString (); if(isfirstlevel) {currenttreenode.expanded=true; }            Else{currenttreenode.expanded=false; } Currenttreenode.remarks=""; Currenttreenode.spritecssclass="folder"; if(Currenttreenode.items = =NULL) {Currenttreenode.items=NewList<cust_treeviewitemmodel>(); } List<es_data_path_mini> Lstchildpath = lstpaths.where (c = c.pid = =currentpath.id).            ToList (); if(Lstchildpath! =NULL&&Lstchildpath.any ()) {Currenttreenode.haschildren=true; foreach(varPathinchLstchildpath) {addchildkendotree (Currenttreenode.items, Path, lstpaths,false); }            }            Else{Currenttreenode.haschildren=false; }            if(CurrentTreeNode.Items.Count = =0) {Currenttreenode.items=NULL;        } lsttree.add (Currenttreenode); }

Third, skills

1, according to the ID of the data to obtain the current record (the primary key must use the full lowercase id, all lowercase, why do I stress?! Because I doubted life on this issue for one hours)

var Bardataitem = Treeview.dataSource.get (Currentselectedid);

2, according to the current record of the UID to get the current record of node, the following barelement is already a node type of value.

var barelement = Treeview.findbyuid (Bardataitem.uid);

3 . Obtain the ID value of the data it binds to by a node:

(' #treeviewFolder '). Data (' Kendotreeview '). DataItem (node). ID

4. gets the text value of the data it binds according to a node:

$ (' #treeviewFolder '). Data (' Kendotreeview '). DataItem (node). Text

5, according to a node to get its parent node

TreeView, Treeview.parent (node)

6. Automatically select a node on the TreeView

var TreeView = $ (' #treeviewFolder '). Data (' Kendotreeview ');
var data = TreeView.dataSource.get (ID);
var SelectItem = Treeview.findbyuid (Data.uid);
Treeview.select (SelectItem);

ASP. NET third-party UI controls Telerik Kendoui usage records for the TreeVIew

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.