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/