原创|其它|编辑:郝浩|2012-10-15 17:25:10.000|阅读 859 次
概述:这个例子演示了如何使用的DevExpress ASPxTreeView的AllowCheckNodes和TreeViewNode的AllowCheck属性管理复选框的可见性。
# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>
这个例子演示了如何使用的DevExpress ASPxTreeView的AllowCheckNodes和TreeViewNode的AllowCheck属性管理复选框的可见性。
开发技术:.NET
开发平台:ASP.NET
相关产品:DevExpress ASPxperience Suite(适用版本:v2010 2.3 ~v2012 1.7)
相关控件:ASPxTreeView
VB.NET语言Default.aspx代码如下:
<%@ Page Language="vb" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %> <%@ Register assembly="DevExpress.Web.v10.2, Version=10.2.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxTreeView" tagprefix="dx" %> <%@ Register assembly="DevExpress.Web.ASPxEditors.v10.2, Version=10.2.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="//www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <dx:ASPxRadioButtonList ID="ASPxRadioButtonList1" runat="server" AutoPostBack="True" ClientIDMode="AutoID" onselectedindexchanged="ASPxRadioButtonList1_SelectedIndexChanged" SelectedIndex="0"> <Items> <dx:ListEditItem Text="Hide all check boxes" Value="HideAll" /> <dx:ListEditItem Text="Show check boxes for leaf nodes only" Value="ShowLeaves" /> <dx:ListEditItem Text="Show all check boxes" Value="Show" /> </Items> </dx:ASPxRadioButtonList> <dx:ASPxTreeView ID="ASPxTreeView1" runat="server" ClientIDMode="AutoID"> <Nodes> <dx:TreeViewNode> <Nodes> <dx:TreeViewNode> <Nodes> <dx:TreeViewNode> </dx:TreeViewNode> <dx:TreeViewNode> </dx:TreeViewNode> </Nodes> </dx:TreeViewNode> <dx:TreeViewNode> </dx:TreeViewNode> </Nodes> </dx:TreeViewNode> <dx:TreeViewNode> <Nodes> <dx:TreeViewNode> </dx:TreeViewNode> <dx:TreeViewNode> </dx:TreeViewNode> <dx:TreeViewNode> </dx:TreeViewNode> <dx:TreeViewNode> </dx:TreeViewNode> </Nodes> </dx:TreeViewNode> </Nodes> </dx:ASPxTreeView> <br /> <br /> <dx:ASPxButton ID="ASPxButton1" runat="server" OnClick="ASPxButton1_Click" Text="Disable checked nodes"> </dx:ASPxButton> <br /> <dx:ASPxButton ID="ASPxButton2" runat="server" OnClick="ASPxButton2_Click" Text="Enable checked nodes"> </dx:ASPxButton> </form> </body> </html>
VB.NET语言Default.aspx.vb代码如下:
Imports Microsoft.VisualBasic Imports System Imports System.Data Imports System.Configuration Imports System.Collections Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Imports DevExpress.Web.ASPxTreeView Imports DevExpress.Web.ASPxEditors Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If (Not IsPostBack) Then ASPxTreeView1.AllowCheckNodes = Not(ASPxRadioButtonList1.SelectedIndex = 0) ASPxTreeView1.ExpandAll() End If End Sub Protected Sub ASPxRadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Dim rblOptions As ASPxRadioButtonList = TryCast(sender, ASPxRadioButtonList) Select Case rblOptions.SelectedIndex Case 0 ASPxTreeView1.AllowCheckNodes = False Case 1 ASPxTreeView1.AllowCheckNodes = True PerformActionOnNodesRecursive(ASPxTreeView1.Nodes, AddressOf AnonymousMethod1) Case 2 ASPxTreeView1.AllowCheckNodes = True PerformActionOnNodesRecursive(ASPxTreeView1.Nodes, AddressOf AnonymousMethod2) End Select End Sub Private Sub AnonymousMethod1(ByVal node As TreeViewNode) node.AllowCheck = node.Nodes.Count = 0 End Sub Private Sub AnonymousMethod2(ByVal node As TreeViewNode) node.AllowCheck = True End Sub Protected Sub PerformActionOnNodesRecursive(ByVal nodes As TreeViewNodeCollection, ByVal action As Action(Of TreeViewNode)) For Each node As TreeViewNode In nodes action(node) If node.Nodes.Count > 0 Then PerformActionOnNodesRecursive(node.Nodes, action) End If Next node End Sub Protected Sub ASPxButton1_Click(ByVal sender As Object, ByVal e As EventArgs) PerformActionOnNodesRecursive(ASPxTreeView1.Nodes, AddressOf AnonymousMethod3) End Sub Private Sub AnonymousMethod3(ByVal node As TreeViewNode) node.Enabled = Not node.Checked End Sub Protected Sub ASPxButton2_Click(ByVal sender As Object, ByVal e As EventArgs) PerformActionOnNodesRecursive(ASPxTreeView1.Nodes, AddressOf AnonymousMethod4) End Sub Private Sub AnonymousMethod4(ByVal node As TreeViewNode) node.Enabled = True End Sub End Class
C#语言Default.aspx代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register assembly="DevExpress.Web.v10.2, Version=10.2.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxTreeView" tagprefix="dx" %> <%@ Register assembly="DevExpress.Web.ASPxEditors.v10.2, Version=10.2.1.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="//www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <!--region #Markup--> <dx:ASPxRadioButtonList ID="ASPxRadioButtonList1" runat="server" AutoPostBack="True" ClientIDMode="AutoID" onselectedindexchanged="ASPxRadioButtonList1_SelectedIndexChanged" SelectedIndex="0"> <Items> <dx:ListEditItem Text="Hide all check boxes" Value="HideAll" /> <dx:ListEditItem Text="Show check boxes for leaf nodes only" Value="ShowLeaves" /> <dx:ListEditItem Text="Show all check boxes" Value="Show" /> </Items> </dx:ASPxRadioButtonList> <dx:ASPxTreeView ID="ASPxTreeView1" runat="server" ClientIDMode="AutoID"> <Nodes> <dx:TreeViewNode> <Nodes> <dx:TreeViewNode> <Nodes> <dx:TreeViewNode> </dx:TreeViewNode> <dx:TreeViewNode> </dx:TreeViewNode> </Nodes> </dx:TreeViewNode> <dx:TreeViewNode> </dx:TreeViewNode> </Nodes> </dx:TreeViewNode> <dx:TreeViewNode> <Nodes> <dx:TreeViewNode> </dx:TreeViewNode> <dx:TreeViewNode> </dx:TreeViewNode> <dx:TreeViewNode> </dx:TreeViewNode> <dx:TreeViewNode> </dx:TreeViewNode> </Nodes> </dx:TreeViewNode> </Nodes> </dx:ASPxTreeView> <br /> <br /> <dx:ASPxButton ID="ASPxButton1" runat="server" OnClick="ASPxButton1_Click" Text="Disable checked nodes"> </dx:ASPxButton> <br /> <dx:ASPxButton ID="ASPxButton2" runat="server" OnClick="ASPxButton2_Click" Text="Enable checked nodes"> </dx:ASPxButton> <!--endregion #Markup--> </form> </body> </html>
C#语言Default.aspx.cs代码如下:
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; #region #Check_Boxes using DevExpress.Web.ASPxTreeView; using DevExpress.Web.ASPxEditors; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ASPxTreeView1.AllowCheckNodes = !(ASPxRadioButtonList1.SelectedIndex == 0); ASPxTreeView1.ExpandAll(); } } protected void ASPxRadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { ASPxRadioButtonList rblOptions = sender as ASPxRadioButtonList; switch (rblOptions.SelectedIndex) { case 0: ASPxTreeView1.AllowCheckNodes = false; break; case 1: ASPxTreeView1.AllowCheckNodes = true; PerformActionOnNodesRecursive(ASPxTreeView1.Nodes, delegate(TreeViewNode node) { node.AllowCheck = node.Nodes.Count == 0; }); break; case 2: ASPxTreeView1.AllowCheckNodes = true; PerformActionOnNodesRecursive(ASPxTreeView1.Nodes, delegate(TreeViewNode node) { node.AllowCheck = true; }); break; } } protected void PerformActionOnNodesRecursive(TreeViewNodeCollection nodes, Action<TreeViewNode> action) { foreach (TreeViewNode node in nodes) { action(node); if (node.Nodes.Count > 0) PerformActionOnNodesRecursive(node.Nodes, action); } } protected void ASPxButton1_Click(object sender, EventArgs e) { PerformActionOnNodesRecursive(ASPxTreeView1.Nodes, delegate(TreeViewNode node) { node.Enabled = !node.Checked;}); } protected void ASPxButton2_Click(object sender, EventArgs e) { PerformActionOnNodesRecursive(ASPxTreeView1.Nodes, delegate(TreeViewNode node) { node.Enabled = true; }); } } #endregion #Check_Boxes
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn
文章转载自:慧都控件网