带线的无限级下拉树列表

简介:

好多年没写文章了
这里就分享点自己原创的一点破代码,效果如图下:
r_%7BDB83491B-1991-48D4-9A9B-69704E20B45
本人的提供的代码如下:

None.gif using System;
None.gif using System.Collections.Generic;
None.gif using System.Text;
None.gif using System.Web.UI.WebControls;
None.gif
None.gif namespace Interface.Common
ExpandedBlockStart.gif {
InBlock.gif    public interface IDropDownTree : IDisposable
ExpandedSubBlockStart.gif    {
ExpandedSubBlockStart.gif        /// <summary>
InBlock.gif        
/// 返回Dictionary里分别对应ID,文本,如果没有子节点返回null
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="parentID">父节点ID</param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        Dictionary<stringstring> GetChildCategory(string parentID);
ExpandedSubBlockStart.gif        /// <summary>
InBlock.gif        
/// 代码里写return new Interface.Common.DropDownTree(this);
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        DropDownTree DropDownTree
ExpandedSubBlockStart.gif        {
InBlock.gif            get;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    public sealed class DropDownTree
ExpandedSubBlockStart.gif    {
InBlock.gif        IDropDownTree _DropDownTree;
InBlock.gif        public DropDownTree(IDropDownTree dropDownTree)
ExpandedSubBlockStart.gif        {
InBlock.gif            _DropDownTree = dropDownTree;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gif        /// <summary>
InBlock.gif        
/// 用于树的前缀
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="IsLast">是否是同级节点中的最后一个</param>
InBlock.gif        
/// <param name="HasChild">本节点是否拥有子节点</param>
InBlock.gif        
/// <param name="ParentString">父节点前缀符号</param>
ExpandedSubBlockEnd.gif        
/// <returns>本节点的前缀</returns>

InBlock.gif        private string GetPreFix(bool isLast, bool hasChild, string parentString)
ExpandedSubBlockStart.gif        {
InBlock.gif            string result = string.Empty;
InBlock.gif            if (!string.IsNullOrEmpty(parentString))
ExpandedSubBlockStart.gif            {
InBlock.gif                parentString = parentString.Remove(parentString.Length - 1).Replace("""").Replace(""" ");
InBlock.gif                result += parentString;
ExpandedSubBlockEnd.gif            }

InBlock.gif            if (isLast)
ExpandedSubBlockStart.gif            {
InBlock.gif                result += "";
ExpandedSubBlockEnd.gif            }

InBlock.gif            else
ExpandedSubBlockStart.gif            {
InBlock.gif                result += "";
ExpandedSubBlockEnd.gif            }

InBlock.gif            if (hasChild)
ExpandedSubBlockStart.gif            {
InBlock.gif                result += "";
ExpandedSubBlockEnd.gif            }

InBlock.gif            else
ExpandedSubBlockStart.gif            {
InBlock.gif                result += "";
ExpandedSubBlockEnd.gif            }

InBlock.gif            return result;
ExpandedSubBlockEnd.gif        }

ContractedSubBlock.gif        绑定下拉菜单
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}


调用方法很简单:
1.继承自IDropDownTree接口
2.实现3个接口方法

实现接口代码示例[Dispose方法自己实现],最主要的是自己实现获得子级的方法
ContractedBlock.gif  IDropDownTree 成员

页面调用代码: 类名.DropDownTree.BindToDropDownList(下拉控件ID);

希望对大伙有点帮助....


版权声明:本文原创发表于博客园,作者为路过秋天,原文链接:http://www.cnblogs.com/cyq1162/archive/2008/04/17/1157507.html

目录
相关文章
|
15天前
|
前端开发 JavaScript
如何处理用户的拖拽排序操作
这个示例展示了如何使用JavaScript处理HTML列表的拖拽排序。通过监听`dragstart`、`dragend`、`dragenter`、`dragleave`、`dragover`和`drop`事件,实现拖拽元素时的视觉反馈和元素位置交换。当用户拖放列表项时,相关事件触发,更新列表顺序,提供直观的交互体验。
|
7月前
|
人工智能 自然语言处理 语音技术
elementUI使用v-for创建无限级导航栏—— 递归组件
elementUI使用v-for创建无限级导航栏—— 递归组件
56 0
|
8月前
|
设计模式 人工智能 安全
没有性能瓶颈的无限级菜单树应该这样设计
以一门网络课程为例,我们设计一个课程的关系结构。比如,我们有Java入门课程、人工智能课程、Java设计模式、源码分析、软技能等,而Java设计模式、源码分析、软技能又属于Java架构师系列课程包,每个课程的定价都不一样。但是,这些课程不论怎么组合,都有一些共性,而且是整体和部分的关系,可以用组合模式来设计。首先创建一个顶层的抽象组件CourseComponent类。
62 0
|
9月前
|
Web App开发 缓存 JavaScript
简洁、巧妙、高效的长列表,无限下拉方案
简洁、巧妙、高效的长列表,无限下拉方案
81 0
|
10月前
|
定位技术
百度地图开发:实现附近距离的筛选功能
百度地图开发:实现附近距离的筛选功能
62 0
|
JavaScript 数据建模 数据格式
【自然框架】n级下拉列表框的原理
  其实原理也很简单,分成两个部分,一个是服务器端,一个是客户端。     首先要设置记录集,这里用DataSet来装载,二级联动,里面就要有两个DataTable;三级联动,里面就要有三个DataTable。
1174 0