您的位置:首页 > 其它

加载出一个有层次的下拉框

2016-05-27 10:35 197 查看
public void getOneClassTree(int classid, System.Web.UI.WebControls.DropDownList cid, int _depth = 0)
{
string texts = "";
string values = "";
int depth = _depth;
BLL.manager_Department BLL_商品 = new BLL.manager_Department();
Model.manager_Department cate = new Model.manager_Department();
//获取商品类别对象
cate = BLL_商品.GetModel(classid);
DataTable dt_Have = SqlHelpers.GetDataTableBySQL("select * from manager_Department where parent_id=" + classid + " order by parent_id");
for (int i = 0; i < depth; i++)
{
texts += " ";
}
values = cate.id.ToString();
if (dt_Have.Rows.Count == 0)
{
texts += " - " + cate.dep_name;
cid.Items.Add(new ListItem(texts, values));
}
else
{
texts += " + " + cate.dep_name;
cid.Items.Add(new ListItem(texts, values));
DataTable classidArry1 = SqlHelpers.GetDataTableBySQL("select * from manager_Department where parent_id=" + classid + " order by parent_id");
foreach (DataRow dr in classidArry1.Rows)
{
getOneClassTree(Convert.ToInt32(dr["id"]), cid, depth + 1);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: