Esempio n. 1
0
        /// <summary>
        /// Gets the items wrapped in a table
        /// </summary>
        /// <param name="nb">The Navbar in which rendering is taking place</param>
        /// <param name="items">The items to render into the group</param>
        /// <returns></returns>
        private string GetChildrenAsTable(NavBar nb, NavBarItems items)
        {
            System.Web.UI.HtmlControls.HtmlTable tbl = new System.Web.UI.HtmlControls.HtmlTable();
            tbl.Border      = 0;
            tbl.CellPadding = 2;
            tbl.CellSpacing = 0;
            tbl.Width       = "100%";

            foreach (NavBarItem itm in items)
            {
                HtmlTableRow tr = new HtmlTableRow();

                string style = string.Empty;
                if (itm.ItemStyle == null || itm.ItemStyle.Base == null)
                {
                    if (nb.DefaultItemStyle == null || nb.DefaultItemStyle.Base == null)
                    {
                        style = string.Empty;
                    }
                    else
                    {
                        style = nb.DefaultItemStyle.Base;
                    }
                }
                else
                {
                    style = itm.ItemStyle.Base;
                }

                string hoverstyle = string.Empty;
                if (itm.ItemStyle == null || itm.ItemStyle.Hover == null)
                {
                    if (nb.DefaultItemStyle == null || nb.DefaultItemStyle.Hover == null)
                    {
                        hoverstyle = string.Empty;
                    }
                    else
                    {
                        hoverstyle = nb.DefaultItemStyle.Hover;
                    }
                }
                else
                {
                    hoverstyle = itm.ItemStyle.Hover;
                }

                tr.Attributes.Add("class", style);
                tr.Style.Add("width", "100%");

                HtmlTableCell td = new HtmlTableCell();
                td.Style.Add("width", "100%");
                td.Attributes.Add("class", style);
                td.Attributes.Add("onmouseover", string.Format("nbItemHighlight(this,'{0}')", hoverstyle));
                td.Attributes.Add("onmouseout", string.Format("nbItemLowlight(this,'{0}')", style));

                HtmlAnchor a = new HtmlAnchor();

                a.HRef = itm.NavigateUrl;
                StringBuilder inner = new StringBuilder();

                if (itm.Image != null && itm.Image.Length > 0)
                {
                    inner.AppendFormat("<img src='{0}'/><br>", itm.Image);
                }

                inner.Append(itm.Text);
                a.InnerHtml = inner.ToString();

                td.Controls.Add(a);

                tr.Cells.Add(td);
                tbl.Rows.Add(tr);
            }

            StringBuilder  sb  = new StringBuilder();
            TextWriter     tw  = new StringWriter(sb);
            HtmlTextWriter htw = new HtmlTextWriter(tw);

            tbl.RenderControl(htw);

            return(sb.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// The only method required for the designer.  Returns the HTML to render onto the
        /// design surface.
        /// </summary>
        /// <returns>HTML of the dummy table.</returns>
        public override string GetDesignTimeHtml()
        {
            NavBar        nb = ((NavBar)Component);
            StringBuilder sb = new StringBuilder();

            sb.Append("<div ");

            if (nb.CssClass != null && nb.CssClass != string.Empty)
            {
                sb.AppendFormat(" class = '{0}' ", nb.CssClass);
            }

            sb.Append(" style='");

            if (!nb.Width.IsEmpty)
            {
                sb.AppendFormat(" Width: {0}; ", nb.Width.ToString());
            }

            if (!nb.Height.IsEmpty)
            {
                sb.AppendFormat(" Height: {0}; ", nb.Height.ToString());
            }

            sb.Append("'>");
            bool expando = false;

            foreach (NavBarBlock bl in nb.Blocks)
            {
                if (bl.Expanded)
                {
                    expando = true;
                    break;
                }
            }

            if (!expando && nb.Blocks.Count > 0)
            {
                nb.Blocks[0].Expanded = true;
            }

            expando = false;

            foreach (NavBarBlock bl in nb.Blocks)
            {
                if (bl.Items.Count > 0)
                {
                    sb.Append("<div");
                    sb.Append(" class='block'");
                    sb.Append(">");

                    //Block Header
                    if (!bl.Expanded)
                    {
                        sb.Append("<div");
                        if (bl.BlockStyle == null || bl.BlockStyle.Closed == null)
                        {
                            if (nb.DefaultBlockStyle == null || nb.DefaultBlockStyle.Closed == null)
                            {
                                sb.Append(" class='' ");
                            }
                            else
                            {
                                sb.AppendFormat(" class = '{0}' ", nb.DefaultBlockStyle.Closed);
                            }
                        }
                        else
                        {
                            sb.AppendFormat(" class = '{0}' ", bl.BlockStyle.Closed);
                        }
                        sb.AppendFormat(" expanded = '{0}' ", "false");
                    }
                    else
                    {
                        sb.Append("<div");
                        if (bl.BlockStyle == null || bl.BlockStyle.Expanded == null)
                        {
                            if (nb.DefaultBlockStyle == null || nb.DefaultBlockStyle.Expanded == null)
                            {
                                sb.Append(" class='' ");
                            }
                            else
                            {
                                sb.AppendFormat(" class = '{0}' ", nb.DefaultBlockStyle.Expanded);
                            }
                        }
                        else
                        {
                            sb.AppendFormat(" class='{0}' ", bl.BlockStyle.Expanded);
                        }

                        sb.AppendFormat(" expanded = '{0}' ", "true");
                    }

                    sb.Append(">");
                    sb.Append(bl.Text);
                    sb.Append("</div>");
                    //End Block Header

                    //Item Area
                    sb.Append("<div");
                    if (bl.BlockStyle == null || bl.BlockStyle.ItemArea == null)
                    {
                        if (nb.DefaultBlockStyle == null || nb.DefaultBlockStyle.ItemArea == null)
                        {
                            sb.Append(" class='' ");
                        }
                        else
                        {
                            sb.AppendFormat(" class='{0}' ", nb.DefaultBlockStyle.ItemArea);
                        }
                    }
                    else
                    {
                        sb.AppendFormat(" class='{0}' ", bl.BlockStyle.ItemArea);
                    }

                    if (!bl.Expanded)
                    {
                        sb.Append(" style='display:none' ");
                    }

                    sb.Append(">");

                    sb.Append(GetChildrenAsTable(nb, bl.Items));

                    sb.Append("</div>");
                    //End Item Area
                    sb.Append("</div>");
                }
            }
            sb.Append("</div>");

            return(sb.ToString());
        }