Dev ComboxTree implementation

Source: Internet
Author: User

This is used in a project. You can back up your notes and share them with us.

The ASPxDropDownEdit ASPxTreeView controls must be used.

The dll corresponding to ASPxDropDownEdit is DevExpress. Web. ASPxEditors. v12.1.dll.

Web. the configuration in config is: <add tagPrefix = "dx" namespace = "DevExpress. web. ASPxEditors "assembly =" DevExpress. web. ASPxEditors. v12.1, Version = 12.1.8.0, Culture = neutral, PublicKeyToken = b88d1754d700e49a "/>

 

The dll corresponding to ASPxTreeView is DevExpress. Web. v12.1.dll.

Web. the configuration in config is: <add tagPrefix = "dx" namespace = "DevExpress. web. ASPxTreeView "assembly =" DevExpress. web. v12.1, Version = 12.1.8.0, Culture = neutral, PublicKeyToken = b88d1754d700e49a "/>

First:

<Dx: ASPxDropDownEdit ID = "ddNodes" runat = "server" ClientInstanceName = "ddNodes" AllowUserInput = "false" Width = "200px"> <DropDownWindowTemplate> <dx: ASPxTreeView ID = "tvNodes" runat = "server" ClientInstanceName = "tvNodes" AllowSelectNode = "true" Success = "true"> <ClientSideEvents NodeClick = "OnNodesTreeViewNodeClick"/> <! -- Js method for assigning values to controls --> </dx: ASPxTreeView> </DropDownWindowTemplate> </dx: ASPxDropDownEdit>

How to assign values to controls using js

function OnNodesTreeViewNodeClick(s, e) {            if (e.node.nodes.length > 0)                return;            ddNodes.SetKeyValue(e.node.name);            ddNodes.SetText(e.node.GetText());            ddNodes.HideDropDown();        }

Background code implementation

ASPxTreeView tvNodes = ddNodes. FindControl ("tvNodes") as ASPxTreeView;
TreeViewCreateNodes (data list, tvNodes. Nodes, "0"); // method for creating TreeViewNodes
TvNodes. SelectedNode = TreeViewSelectedNode (tvNodes, '5'); // 5 indicates the ID of the selected node.
DdNodes. Text = tvNodes. SelectedNode. Text;
DdNodes. KeyValue = tvNodes. SelectedNode. Name;

/// <Summary>
/// Create a TreeViewNodes Node
/// </Summary>
/// <Param name = "table"> </param>
/// <Param name = "nodesCollection"> </param>
/// <Param name = "parentID"> </param>
Public static void TreeViewCreateNodes (IList <T> table, TreeViewNodeCollection nodesCollection, string parentID)
{
For (int I = 0; I <table. Count; I ++)
{
If (table [I]. ParentID = parentID)
{
TreeViewNode node = new TreeViewNode (table [I]. Name, table [I]. ID );
NodesCollection. Add (node );
TreeViewCreateNodes (table, node. Nodes, node. Name );
}
}
}

/// <Summary>
/// Obtain the selected node of TreeViewNodes
/// </Summary>
/// <Param name = "tvn"> </param>
/// <Param name = "selectID"> </param>
/// <Returns> </returns>
Public void TreeViewSelectedNode (ASPxTreeView tvNodes, string selectID)
{
Foreach (TreeViewNode tvn in tvNodes. Nodes)
{
TvNodes. SelectedNode = TreeViewSelectedNode (tvn, selectID );
If (tvNodes. SelectedNode! = Null)
Break;
}
}

/// <Summary>
/// Obtain the selected node of TreeViewNodes
/// </Summary>
/// <Param name = "tvn"> </param>
/// <Param name = "selectID"> </param>
/// <Returns> </returns>
Private TreeViewNode TreeViewSelectedNode (TreeViewNode tvn, string selectID)
{
If (tvn. Name = selectID)
{
Return tvn;
}
Else if (tvn. Nodes. Count> 0)
{
Foreach (TreeViewNode tvnChild in tvn. Nodes)
{
TreeViewNode tvns = TreeViewSelectedNode (tvnChild, selectID );
If (tvns! = Null)
Return tvns;
}
}
Return null;
}

Reprinted reference please retain copyright http://www.cnblogs.com/xushaonian/p/3230181.html BY www.gkxsn.com

Cup http://988777.taobao.com/

Shoe http://xiaobenxie.taobao.com/

Related Article

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.