效果:
┣专题报道
│┣思政教育
│┣就业指导
│┣考研指南
┣文学艺术
│┣散文
││┣在水一方
││┣情感倾诉
代码:
protected void Page_Load(object sender, EventArgs e)
{
suoji = "┣";//静态变量,这里初始化
DropDownList dp = new DropDownList();
BindDropList2(Dp,0);
Form.Controls.Add(dp);
}
static string suoji = "┣";
public int BindDropList2(DropDownList Dp, int ParentID)
{
try
{
DataTable dt = MyDoSql.GetDt("select Id,ParentID,ItemText from MenuItem where ParentID=" + ParentID + " order by OrderIndex asc,id asc");
for (int i = 0; i < dt.Rows.Count; i++)
{
ListItem Li = new ListItem(suoji + dt.Rows[i]["ItemText"].ToString(), dt.Rows[i]["Id"].ToString());
Dp.Items.Add(Li);
suoji = "| " + suoji;
BindDropList2(Dp, int.Parse(dt.Rows[i]["Id"].ToString()));
suoji = suoji.Substring(("| ").Length, suoji.Length - ("| ").Length);
}
return 1;
}
catch
{
return 0;
}
}