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

本人的提供的代码如下:

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<stringstring> GetChildCategory(string parentID);
        
/// <summary>
        
/// 代码里写return new Interface.Common.DropDownTree(this);
        
/// </summary>

        DropDownTree DropDownTree
        
{
            
get;
        }

    }

    
public sealed class DropDownTree
    
{
        IDropDownTree _DropDownTree;
        
public DropDownTree(IDropDownTree dropDownTree)
        
{
            _DropDownTree 
= dropDownTree;
        }

        
/// <summary>
        
/// 用于树的前缀
        
/// </summary>
        
/// <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 
+= "";
            }

            
else
            
{
                result 
+= "";
            }

            
return result;
        }

        
绑定下拉菜单
    }

}


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

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

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

希望对大伙有点帮助....
posted on 2008-04-17 10:20  路过秋天  阅读(6298)  评论(34编辑  收藏  举报
路过秋天