All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
Asp.net下实现隐藏真实下载地址(可以实现简单的防盗链)_[Asp.Net教程]
javascript实现网页图片等比例缩放_JavaScript技术_编程技术
如何测试,Macintosh,Web,服务器_php资料_编程技术
谈PHP生成静态页面_php资料_编程技术
PHP技巧:动态URL静态化_[PHP教程]
delphi设置提示信息
PHP5中PDO的简单使用_php资料_编程技术
GDI+ 坐标系类型
初学者来看:绝对简单易学的PHP入门教程_php资料_编程技术
sql 2005 express 远程访问和sa密码的问题_[SQL Server教程]
Reading number is top 10 pictures
The little girl with long hair2
Female star bikini
The money of more than 100 countries and regions20
你是左脑型还是右脑型
贩卖儿童者必须判死刑
清扫五脏垃圾,我有绝招
Small s breast enhancement demonstration
30 beautiful school beauty6
到底是谁撞谁呀?
Summer is most suitable for young people to travel in China4
Download software ranking
matrix2
ASP.NET.2.0.XML.高级编程(第3版)
C#编程思想
Twenty piece of palm leaf
功夫熊猫2(下集)
Unix video tutorial6
Desire a peach blossom
Sora aoi, the nurse, uniform ,nursing assistant
电车之狼R
Boxer's Top ten classic battle9
归海一刀 published in(发表于) 2014/1/30 1:00:03 Edit(编辑)
asp.net带线的无限级下拉树列表_[Asp.Net教程]

asp.net带线的无限级下拉树列表_[Asp.Net教程]

asp.net带线的无限级下拉树列表_[Asp.Net教程]

好多年没写文章了
这里就分享点自己原创的一点破代码,效果如图下:



本人的提供的代码如下:



using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;


namespace Interface.Common
{
public interface IDropDownTree : IDisposable
{
/**////


/// 返回Dictionary里分别对应ID,文本,如果没有子节点返回null
///

/// 父节点ID
///
Dictionary GetChildCategory(string parentID);
/**////
/// 代码里写return new Interface.Common.DropDownTree(this);
///

DropDownTree DropDownTree
{
get;
}
}
public sealed class DropDownTree
{
IDropDownTree _DropDownTree;
public DropDownTree(IDropDownTree dropDownTree)
{
_DropDownTree = dropDownTree;
}
/**////
/// 用于树的前缀
///

/// 是否是同级节点中的最后一个
/// 本节点是否拥有子节点
/// 父节点前缀符号
/// 本节点的前缀
private string GetPreFix(bool isLast, bool hasChild, string parentString)
{
string result = string.Empty;
if (!string.IsNullOrEmpty(parentString))
{
parentString = parentString.Remove(parentString.Length - 1).Replace("├", "│").Replace("└", " ");
result += parentString;
}
if (isLast)
{
result += "└";
}
else
{
result += "├";
}
if (hasChild)
{
result += "┬";
}
else
{
result += "─";
}
return result;
}
绑定下拉菜单#region 绑定下拉菜单


/**////


/// 绑定连动级的下拉菜单
///

/// 传进一个被绑定的DropDownList
/// 被排除绑定的节点ID
/// 是否自动释放
public void BindToDropDownList(DropDownList ddlGoodsType, string removeID,string parentID, bool autoDispose)
{
if (ddlGoodsType != null)
{
ListItem listItem = null;
string currentID = parentID;//根节点/父ID
string currentSign = string.Empty;//当前节点符号;
string parrentSign = string.Empty; //父节点符号;
bool HasChild = true;//是否有子
Queue parentKeyList = new Queue();//存 有子节点的 节点ID
Queue parentSignList = new Queue();//对应节点ID的前缀符号
int itemIndexOf = 0;//父节点所在的位置 
while (HasChild)
{
int lastOneCount = 1;//用于计算在同级别中是否最后一个
Dictionary childList = _DropDownTree.GetChildCategory(currentID);// 得到子节点列表
if (childList != null && childList.Count > 0)
{
if (!string.IsNullOrEmpty(removeID) && childList.ContainsKey(removeID))
{
childList.Remove(removeID);
}
foreach (KeyValuePair entry in childList)
{
if (_DropDownTree.GetChildCategory(entry.Key) != null)//存在子
{
currentSign = GetPreFix(lastOneCount == childList.Count, true, parrentSign);
listItem = new ListItem(currentSign + entry.Value, entry.Key);


parentKeyList.Enqueue(entry.Key);//当前的节点ID
parentSignList.Enqueue(currentSign);//当前的节点符号
}
else//不存在子
{
currentSign = GetPreFix(lastOneCount == childList.Count, false, parrentSign);
listItem = new ListItem(currentSign + entry.Value, entry.Key);
}
if (ddlGoodsType.Items.Count != 0)
{
itemIndexOf = string.IsNullOrEmpty(currentID) ? itemIndexOf + 1 : ddlGoodsType.Items.IndexOf(ddlGoodsType.Items.FindByValue(currentID)) + lastOneCount;
}
ddlGoodsType.Items.Insert(itemIndexOf, listItem);//添加子节点
lastOneCount++;
}
if (parentKeyList.Count > 0)//存在子节点时
{
currentID = parentKeyList.Dequeue();
parrentSign = parentSignList.Dequeue();
}
else
{
HasChild = false;
}
}
else
{
break;
}



}
if (autoDispose)
{
_DropDownTree.Dispose();
}


}
}
/**////


/// 绑定连动级的下拉菜单
///

/// 传进一个被绑定的DropDownList
public void BindToDropDownList(DropDownList ddlGoodsType)
{
BindToDropDownList(ddlGoodsType, string.Empty,null, true);
}
/**////
/// 绑定连动级的下拉菜单
///

/// 传进一个被绑定的DropDownList
/// 被排除的ID
public void BindToDropDownList(DropDownList ddlGoodsType, string removeID)
{
BindToDropDownList(ddlGoodsType, removeID,null, true);
}
/**////
/// 绑定连动级的下拉菜单
///

/// 传进一个被绑定的DropDownList
/// 被排除的ID,若没有,传null
/// 起始父ID
public void BindToDropDownList(DropDownList ddlGoodsType, string removeID,string parentID)
{
BindToDropDownList(ddlGoodsType, removeID,parentID, true);
}
#endregion
}
}


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


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


public Dictionary GetChildCategory(string parentID)
{
string where = "ParentID='" + parentID + "'";
if (string.IsNullOrEmpty(parentID))
{
where = "ParentID is null or ParentID='" + Guid.Empty + "'";
}
List _GoodsCategoryList = SelectList(0, where, string.Empty, false);
if (_GoodsCategoryList != null && _GoodsCategoryList.Count > 0)
{
Dictionary categoryList = new Dictionary();
for (int i = 0; i < _GoodsCategoryList.Count; i++)
{
categoryList.Add(_GoodsCategoryList[i].ID.ToString(), _GoodsCategoryList[i].GategoryName);
}
return categoryList;
}
return null;
}


public Interface.Common.DropDownTree DropDownTree
{
get { return new Interface.Common.DropDownTree(this); }
}


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


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


来源:http://www.cnblogs.com/cyq1162







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.