Пример #1
0
        private void LoadTypeParent()
        {
            try
            {
                var CatList = (
                    from t2 in db.TYPE_COMPANies
                    select new
                {
                    TYPE_ID = t2.TYPE_NAME == "-------Root-------" ? 0 : t2.TYPE_ID,
                    TYPE_PARENT = t2.TYPE_PARENT,
                    TYPE_RANK = t2.TYPE_RANK,
                    TYPE_NAME = t2.TYPE_NAME
                }
                    );

                if (CatList.ToList().Count > 0)
                {
                    DataRelation relCat;
                    DataTable    tbl = DataUtil.LINQToDataTable(CatList);
                    DataSet      ds  = new DataSet();
                    ds.Tables.Add(tbl);

                    tbl.PrimaryKey = new DataColumn[] { tbl.Columns["TYPE_ID"] };
                    relCat         = new DataRelation("TYPE_PARENT", ds.Tables[0].Columns["TYPE_ID"], ds.Tables[0].Columns["TYPE_PARENT"], false);

                    ds.Relations.Add(relCat);
                    DataSet   dsCat    = ds.Clone();
                    DataTable CatTable = ds.Tables[0];

                    unit_data.TransformTableWithSpace(ref CatTable, dsCat.Tables[0], relCat, null);

                    Drmenu_parent.DataSource     = dsCat.Tables[0];
                    Drmenu_parent.DataTextField  = "TYPE_NAME";
                    Drmenu_parent.DataValueField = "TYPE_ID";
                    Drmenu_parent.DataBind();
                }
                else
                {
                    DataTable dt = new DataTable("Newtable");

                    dt.Columns.Add(new DataColumn("TYPE_ID"));
                    dt.Columns.Add(new DataColumn("TYPE_NAME"));

                    DataRow row = dt.NewRow();
                    row["TYPE_ID"]   = 0;
                    row["TYPE_NAME"] = "-------Root-------";
                    dt.Rows.Add(row);

                    Drmenu_parent.DataTextField  = "TYPE_NAME";
                    Drmenu_parent.DataValueField = "TYPE_ID";
                    Drmenu_parent.DataSource     = dt;
                    Drmenu_parent.DataBind();
                }
            }
            catch (Exception ex)
            {
                clsVproErrorHandler.HandlerError(ex);
            }
        }
        private void Loadmenu_parent()
        {
            var list = db.MENU_PARENTs.Where(n => n.MENU_RANK == 1);

            Drmenu_parent.DataValueField = "MENU_PAR_ID";
            Drmenu_parent.DataTextField  = "MENU_NAME";
            Drmenu_parent.DataSource     = list;
            Drmenu_parent.DataBind();
            ListItem l = new ListItem("--- Root ---", "0");

            l.Selected = true;
            Drmenu_parent.Items.Insert(0, l);
        }