aspnet-devexpress-dot-web-dot-aspxtreeview-972e305d.md
Allows you to save and restore the previously saved layout of the ASPxTreeView.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
public event ASPxClientLayoutHandler ClientLayout
Public Event ClientLayout As ASPxClientLayoutHandler
The ClientLayout event's data class is ASPxClientLayoutArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| LayoutData | Gets or sets the layout data. |
| LayoutMode | Indicates whether a control’s layout should be saved or restored. |
Handle the ClientLayout event to save and restore the ASPxTreeView’s layout from a data store.
Save LayoutThe event parameter’s LayoutMode property returns Saving. The LayoutData property contains the ASPxTreeView’s current layout that should be saved, for example, to a database.Restore LayoutThe LayoutMode property returns Loading. Read the ASPxTreeView’s layout data from a data store and assign it to the LayoutData property.
<dx:ASPxTreeView ID="virtualTree" runat="server"
OnVirtualModeCreateChildren="virtualTree_VirtualModeCreateChildren"
OnClientLayout="virtualTree_ClientLayout"
OnExpandedChanging="virtualTree_ExpandedChanging" />
protected void virtualTree_VirtualModeCreateChildren(object source, TreeViewVirtualModeCreateChildrenEventArgs e) {
List<TreeViewVirtualNode> children = new List<TreeViewVirtualNode>();
if (e.NodeName == null) {
AppendChildNode(children, "me", "Me!", false);
AppendChildNode(children, "family", "Family", false);
AppendChildNode(children, "friends", "Friends", false);
}
else {
if (e.NodeName == "me") {
AppendChildNode(children, "clean", "Cleaning");
AppendChildNode(children, "drive", "Driving", false);
AppendChildNode(children, "play", "Playing");
}
else if (e.NodeName == "family") {
AppendChildNode(children, "anthony", "Anthony", false);
AppendChildNode(children, "chris", "Chris");
}
else if (e.NodeName == "friends") {
AppendChildNode(children, "john", "John", false);
AppendChildNode(children, "ram", "Ram");
}
else if (e.NodeName == "drive") {
AppendChildNode(children, "crv", "CRV");
AppendChildNode(children, "bmw", "BMW");
AppendChildNode(children, "kluger", "Kluger");
}
else if (e.NodeName == "anthony") {
AppendChildNode(children, "run", "Running");
AppendChildNode(children, "swim", "Swimming");
}
else if (e.NodeName == "john") {
AppendChildNode(children, "read", "Reading");
AppendChildNode(children, "test", "Testing");
}
}
e.Children = children;
}
protected void virtualTree_ClientLayout(object sender, ASPxClientLayoutArgs e) {
if (e.LayoutMode == ClientLayoutMode.Loading) {
if (Session["layout"] != null)
e.LayoutData = Session["layout"].ToString();
}
else {
Session["layout"] = e.LayoutData;
}
}
private void AppendChildNode(IList<TreeViewVirtualNode> nodeList, string nodeName, string nodeText) {
AppendChildNode(nodeList, nodeName, nodeText, true);
}
private void AppendChildNode(IList<TreeViewVirtualNode> nodeList, string nodeName, string nodeText, bool isLeaf) {
TreeViewVirtualNode node = new TreeViewVirtualNode(nodeName, nodeText);
node.IsLeaf = isLeaf;
nodeList.Add(node);
}
protected void virtualTree_ExpandedChanging(object source, TreeViewNodeCancelEventArgs e) {
}
Protected Sub virtualTree_VirtualModeCreateChildren(ByVal source As Object, ByVal e As TreeViewVirtualModeCreateChildrenEventArgs)
Dim children As New List(Of TreeViewVirtualNode)()
If e.NodeName Is Nothing Then
AppendChildNode(children, "me", "Me!", False)
AppendChildNode(children, "family", "Family", False)
AppendChildNode(children, "friends", "Friends", False)
Else
If e.NodeName = "me" Then
AppendChildNode(children, "clean", "Cleaning")
AppendChildNode(children, "drive", "Driving", False)
AppendChildNode(children, "play", "Playing")
ElseIf e.NodeName = "family" Then
AppendChildNode(children, "anthony", "Anthony", False)
AppendChildNode(children, "chris", "Chris")
ElseIf e.NodeName = "friends" Then
AppendChildNode(children, "john", "John", False)
AppendChildNode(children, "ram", "Ram")
ElseIf e.NodeName = "drive" Then
AppendChildNode(children, "crv", "CRV")
AppendChildNode(children, "bmw", "BMW")
AppendChildNode(children, "kluger", "Kluger")
ElseIf e.NodeName = "anthony" Then
AppendChildNode(children, "run", "Running")
AppendChildNode(children, "swim", "Swimming")
ElseIf e.NodeName = "john" Then
AppendChildNode(children, "read", "Reading")
AppendChildNode(children, "test", "Testing")
End If
End If
e.Children = children
End Sub
Protected Sub virtualTree_ClientLayout(ByVal sender As Object, ByVal e As ASPxClientLayoutArgs)
If e.LayoutMode = ClientLayoutMode.Loading Then
If Session("layout") IsNot Nothing Then
e.LayoutData = Session("layout").ToString()
End If
Else
Session("layout") = e.LayoutData
End If
End Sub
Private Sub AppendChildNode(ByVal nodeList As IList(Of TreeViewVirtualNode), ByVal nodeName As String, ByVal nodeText As String)
AppendChildNode(nodeList, nodeName, nodeText, True)
End Sub
Private Sub AppendChildNode(ByVal nodeList As IList(Of TreeViewVirtualNode), ByVal nodeName As String, ByVal nodeText As String, ByVal isLeaf As Boolean)
Dim node As New TreeViewVirtualNode(nodeName, nodeText)
node.IsLeaf = isLeaf
nodeList.Add(node)
End Sub
Protected Sub virtualTree_ExpandedChanging(ByVal source As Object, ByVal e As TreeViewNodeCancelEventArgs)
End Sub
See Also