Esempio n. 1
0
        private string RenderMonths(SortedDictionary <DateTime, int> Months)
        {
            if (Months.Keys.Count == 0)
            {
                return(string.Empty);
            }

            HtmlGenericControl ul = new HtmlGenericControl("ul");

            ul.Attributes.Add("id", "blogMonthList");
            HtmlGenericControl year = null;
            HtmlGenericControl list = null;
            int current             = 0;

            foreach (DateTime date in Months.Keys)
            {
                if (current == 0)
                {
                    current = date.Year;
                }

                if (date.Year > current || ul.Controls.Count == 0)
                {
                    list    = new HtmlGenericControl("ul");
                    list.ID = "year" + date.Year.ToString();

                    year = new HtmlGenericControl("li");
                    year.Attributes.Add("class", "year");
                    year.InnerHtml = date.Year.ToString();
                    year.Controls.Add(list);

                    ul.Controls.AddAt(0, year);
                }

                HtmlGenericControl li = new HtmlGenericControl("li");

                HtmlAnchor anc = new HtmlAnchor();
                string     url = SEOHelper.GetBlogUrlByMonth(date);
                anc.HRef      = url;
                anc.InnerHtml = new DateTime(date.Year, date.Month, 1).ToString("MMMM") + " (" + Months[date] + ")";

                li.Controls.Add(anc);
                list.Controls.AddAt(0, li);
                current = date.Year;
            }

            StringWriter sw = new StringWriter();

            ul.RenderControl(new HtmlTextWriter(sw));
            return(sw.ToString());
        }