示例#1
0
        public override void DataBind()
        {
            _Bound = false;

            if (this.DataSource == null)
            {
                throw new NullReferenceException("DataSource cannot be null");
            }

            if (!this.DataSource.Columns.Contains("MenuText"))
            {
                throw new DataException("DataSource must contain the column \"MenuText\"");
            }

            _ParentItems.Clear();

            DataRow[] parents = this.DataSource.Select("MenuParentID = 0");

            foreach (DataRow pdr in parents)
            {
                AccordionParentItem p = new AccordionParentItem();
                if (pdr["MenuText"] == DBNull.Value)
                {
                    throw new DataException("Column \"MenuText\" cannot be null.");
                }
                p.Text        = pdr["MenuText"].ToString();
                p.NavigateURL = Utility.ConvertTo(pdr["MenuURL"], "#");
                p.Visible     = Utility.ConvertTo(pdr["MenuVisible"], false);

                DataRow[] children = this.DataSource.Select("MenuParentID = " + pdr["MenuID"].ToString());
                foreach (DataRow cdr in children)
                {
                    AccordionChildItem c = new AccordionChildItem();
                    if (cdr["MenuText"] == DBNull.Value)
                    {
                        throw new DataException("Column \"MenuText\" cannot be null.");
                    }
                    c.Text        = cdr["MenuText"].ToString();
                    c.NavigateURL = Utility.ConvertTo(cdr["MenuURL"], "#");
                    c.Visible     = Utility.ConvertTo(cdr["MenuVisible"], false);

                    p.ChildItems.Add(c);
                }

                _ParentItems.Add(p);
            }

            _Bound = true;

            base.DataBind();
        }
示例#2
0
        public AccordionChildItem FindChild(string text)
        {
            AccordionChildItem result = null;

            foreach (AccordionChildItem c in _ChildItems)
            {
                if (c.Text == text)
                {
                    result = c;
                    break;
                }
            }

            return(result);
        }