绑定递归数据

  private IList<Model.Menus> ModelParent(DataTable dt, int parentid, IList<Model.Menus> ddl, string str)
        {
            string str_;
            string slt;
            slt = string.Format("parentid={0}", parentid);
            DataRow[] drarr = dt.Select(slt);
            foreach (DataRow dr in drarr)
            {
                if (parentid == 0)
                {
                    str_ = "";
                }
                else
                {
                    str_ = "";
                }
                Model.Menus model=new Model.Menus();
                if (dr["MenuID"] != null && dr["MenuID"].ToString() != "")
                {
                    model.MenuID = int.Parse(dr["MenuID"].ToString());
                }
                if (dr["RankID"] != null)
                {
                    model.RankID = dr["RankID"].ToString();
                }
                if (dr["TypeID"] != null && dr["TypeID"].ToString() != "")
                {
                    model.TypeID = int.Parse(dr["TypeID"].ToString());
                }
                if (dr["MenuName"] != null)
                {
                    model.MenuName = str + str_ + dr["MenuName"].ToString();
                }
                if (dr["ParentID"] != null && dr["ParentID"].ToString() != "")
                {
                    model.ParentID = int.Parse(dr["ParentID"].ToString());
                }
                if (dr["ParentPath"] != null)
                {
                    model.ParentPath = dr["ParentPath"].ToString();
                }
                if (dr["MenuDepth"] != null && dr["MenuDepth"].ToString() != "")
                {
                    model.MenuDepth = int.Parse(dr["MenuDepth"].ToString());
                }
                if (dr["PrevID"] != null && dr["PrevID"].ToString() != "")
                {
                    model.PrevID = int.Parse(dr["PrevID"].ToString());
                }
                if (dr["NextID"] != null && dr["NextID"].ToString() != "")
                {
                    model.NextID = int.Parse(dr["NextID"].ToString());
                }
                if (dr["OrderID"] != null && dr["OrderID"].ToString() != "")
                {
                    model.OrderID = int.Parse(dr["OrderID"].ToString());
                }
                if (dr["ChildCount"] != null && dr["ChildCount"].ToString() != "")
                {
                    model.ChildCount = int.Parse(dr["ChildCount"].ToString());
                }
                if (dr["MenuNewsCount"] != null && dr["MenuNewsCount"].ToString() != "")
                {
                    model.MenuNewsCount = int.Parse(dr["MenuNewsCount"].ToString());
                }
                if (dr["Content"] != null)
                {
                    model.Content = dr["Content"].ToString();
                }
                if (dr["Visible"] != null && dr["Visible"].ToString() != "")
                {
                    if ((dr["Visible"].ToString() == "1") || (dr["Visible"].ToString().ToLower() == "true"))
                    {
                        model.Visible = true;
                    }
                    else
                    {
                        model.Visible = false;
                    }
                }
                if (dr["ViewAmount"] != null && dr["ViewAmount"].ToString() != "")
                {
                    model.ViewAmount = int.Parse(dr["ViewAmount"].ToString());
                }
                if (dr["LinkAddr"] != null)
                {
                    model.LinkAddr = dr["LinkAddr"].ToString();
                }
                if (dr["Template"] != null && dr["Template"].ToString() != "")
                {
                    model.Template = int.Parse(dr["Template"].ToString());
                }
                int parent_id = Convert.ToInt32(model.MenuID);
                ddl.Add(model);
                ModelParent(dt, parent_id, ddl, str + "..");
            }
            return ddl;
        }

 

posted @ 2013-09-16 15:33  程序新青年  阅读(227)  评论(0编辑  收藏  举报
============================================================================== 青春匆匆,很多人都有自己的座右铭,鞭策自己前进,当没看到座右铭的时候又忘了自己要干什么,就这样天天立志,志天天立,最终还是那个初出茅庐的小菜鸟。从现在开始,慢慢去改掉懒惰的习惯。慢慢去加强学习,直到慢慢成功。==============================================================================