由于工作需要特扩展了一下已有的DropDownList控件,使其能显示树状结构的数据,主要用于那些有层次关系的数据显示。
如下图所示:一个继承于DropDownList的树状控件
该控件为无限级扩展的,只需要指定其子节点字段名(默认为ID),父节点字段名(默认为parentID),以及第一层父节点的值即可(默认为0)。

1.首先定义常量
一个继承于DropDownList的树状控件protected const string strT="";
一个继承于DropDownList的树状控件
protected const string strL="";
一个继承于DropDownList的树状控件
protected const string strI="";
一个继承于DropDownList的树状控件
protected DataTable tempTable;
一个继承于DropDownList的树状控件
protected int lay = 0;//节点层数
一个继承于DropDownList的树状控件
protected int level=0;//DropDownList顺序

2.添加属性
        }

3.计算当前节点所在的层以及是否为子节点,是否有兄弟节点等函数,用于生成树形
        }

4.递归生成树形
        }

5.绑定数据
        }
使用的时候调用该函数进行数据绑定!

请大家多多指教以便改进,谢谢!

相关文章: