DropDownList 绑定多级菜单

 private void BindDDL(int zfid)
    { string sql = "SELECT id, cntitle ,fid  FROM T_lm  where fid=" + zfid + " and ty<>4 and isshow=1 order by [sort] asc";
        DataSet ds = Db.GreatDs(sql);
        DataView treedv = new DataView(ds.Tables[0]);
        foreach (DataRowView Row in treedv)
        {
            ddlm.Items.Add(new ListItem("├" + Row["cntitle"].ToString(), Row["id"].ToString()));
            if (sc.tonum(Row["id"].ToString()) > 0)
            {
                string sql1 = "select id, cntitle ,fid from T_lm where fid=" + Row["id"].ToString() + "  and ty<>4 and isshow=1";
                DataSet ds1 = Db.GreatDs(sql1);
                DataView treedv1 = new DataView(ds1.Tables[0]);
                foreach (DataRowView Row1 in treedv1)
                {                   
                    ddlm.Items.Add(new ListItem("--"+"├" + Row1["cntitle"].ToString(), Row1["id"].ToString()));
                  
                }
            }
        }
        ddlm.Items.Insert(0, new ListItem("--请选择栏目--", "0"));

}

<asp:DropDownList ID="ddlm" runat="server">
        </asp:DropDownList>

posted @ 2012-09-05 09:37  沅江  阅读(334)  评论(0编辑  收藏  举报