好多年沒寫文章了
這裡就分享點自己原創的一點破代碼,效果如圖下:
本人的提供的代碼如下:
using system;
using system.collections.generic;
using system.text;
using system.web.ui.webcontrols;
namespace interface.common
{
public interface idropdowntree : idisposable
{
/// <summary>
/// 傳回dictionary裡分别對應id,文本,如果沒有子節點傳回null
/// </summary>
/// <param name="parentid">父節點id</param>
/// <returns></returns>
dictionary<string, string> getchildcategory(string parentid);
/// 代碼裡寫return new interface.common.dropdowntree(this);
dropdowntree dropdowntree
{
get;
}
}
public sealed class dropdowntree
idropdowntree _dropdowntree;
public dropdowntree(idropdowntree dropdowntree)
_dropdowntree = dropdowntree;
/// 用于樹的字首
/// <param name="islast">是否是同級節點中的最後一個</param>
/// <param name="haschild">本節點是否擁有子節點</param>
/// <param name="parentstring">父節點字首符号</param>
/// <returns>本節點的字首</returns>
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 += "┬";
result += "─";
return result;
綁定下拉菜單
}
調用方法很簡單:
1.繼承自idropdowntree接口
2.實作3個接口方法
實作接口代碼示例[dispose方法自己實作],最主要的是自己實作獲得子級的方法
idropdowntree 成員
頁面調用代碼: 類名.dropdowntree.bindtodropdownlist(下拉控件id);
希望對大夥有點幫助....
版權聲明:本文原創發表于部落格園,作者為路過秋天,原文連結:http://www.cnblogs.com/cyq1162/archive/2008/04/17/1157507.html