加载出一个有层次的下拉框
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);
}
}
}