asp.net使用DataGridTree实现下拉树的方法

2019-05-23 07:25:39丽君

        /// <param name="removeid">被排除的id</param>
        public void bindtodropdownlist(dropdownlist ddlgoodstype, string removeid)
        {
            bindtodropdownlist(ddlgoodstype, removeid,null, true);
        }
        /**//// <summary>
        /// 绑定连动级的下拉菜单
        /// </summary>
        /// <param name="ddlgoodstype">传进一个被绑定的dropdownlist</param>
        /// <param name="removeid">被排除的id,若没有,传null</param>
        /// <param name="parentid">起始父id</param>
        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<string, string> getchildcategory(string parentid)
{
    string where = "parentid='" + parentid + "'";
    if (string.isnullorempty(parentid))
    {
 where = "parentid is null or parentid='" + guid.empty + "'";
    }
    list<goodscategorybean> _goodscategorylist = selectlist(0, where, string.empty, false);
    if (_goodscategorylist != null && _goodscategorylist.count > 0)
    {
 dictionary<string, string> categorylist = new dictionary<string, string>();
 for (int i = 0; i < _goodscategorylist.count; i++)
 {
     categorylist.add(_goodscategorylist[i].id.tostring(), _goodscategorylist[i].gategoryname);
 }
 return categorylist;
    }//51aspx.com
    return null;
}
public interface.common.dropdowntree dropdowntree
{
    get { return new interface.common.dropdowntree(this); }
}
#endregion
页面调用代码: 类名.dropdowntree.bindtodropdownlist(下拉控件id);