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(); }
public AccordionParentItem FindParent(string text) { AccordionParentItem result = null; foreach (AccordionParentItem p in _ParentItems) { if (p.Text == text) { result = p; break; } } return(result); }