void WeblogCalendar_Load(object sender, EventArgs e) { SharedBasePage requestPage = this.Page as SharedBasePage; if (requestPage.SiteConfig.AdjustDisplayTimeZone) { daysWithEntries = requestPage.DataService.GetDaysWithEntries(requestPage.SiteConfig.GetConfiguredTimeZone()); newtelligence.DasBlog.Util.WindowsTimeZone tz = requestPage.SiteConfig.GetConfiguredTimeZone(); this.TodaysDate = tz.ToLocalTime(DateTime.Now.ToUniversalTime()); } else { daysWithEntries = requestPage.DataService.GetDaysWithEntries(new newtelligence.DasBlog.Util.UTCTimeZone()); } // TSC: we have collected a date from the __EVENTARGUMENT if the __EVENTTARGET // was holding the name from our weblogCalender in the SharedBasePage, // so we supress the overwriting here if ( (Parent.Page.Request.QueryString["date"] != null && Parent.Page.Request.Params["__EVENTARGUMENT"] == null ) || (Parent.Page.Request.QueryString["date"] != null && Parent.Page.Request.Params["__EVENTTARGET"] != null && Parent.Page.Request.Params["__EVENTTARGET"].IndexOf(this.ID) == -1 ) ) { try { string _mDate = Parent.Page.Request.QueryString["date"]; this.VisibleDate = new System.DateTime(Convert.ToInt16(_mDate.Substring(0, 4)), Convert.ToInt16(_mDate.Substring(5, 2)), 1); } catch { // supress } } }
protected void CommentView_PreRender(object sender, System.EventArgs e) { SharedBasePage requestPage = Page as SharedBasePage; string entryId = (string)ViewState["entryId"]; bool obfuscateEmail = requestPage.SiteConfig.ObfuscateEmail; Entry entry = requestPage.DataService.GetEntry(entryId); if (entry != null) { //Modified 10-3-03 HPierson //Render the day template with just the single entry, rather than the item template //Modified 12-8-03 HPierson //Using entry.CreatedLocalTime causes a bug when dasBlog is not configured to be in //the same time zone as the server. Instead, we use the configured WindowsTimeZone //to calculate the dasBlog configured local time for the entry requestPage.WeblogEntries.Add(entry); if (requestPage.SiteConfig.AdjustDisplayTimeZone) { newtelligence.DasBlog.Util.WindowsTimeZone wtz = requestPage.SiteConfig.GetConfiguredTimeZone(); requestPage.ProcessDayTemplate(wtz.ToLocalTime(entry.CreatedUtc), commentViewContent); } else { requestPage.ProcessDayTemplate(entry.CreatedUtc, commentViewContent); } HtmlAnchor commentStart = new HtmlAnchor(); commentStart.Name = "commentstart"; commentViewContent.Controls.Add(commentStart); // Show all public comments, or all contents if you can approve them // This way all non-public comments remain hidden, when you no longer require approval. bool allComments = SiteSecurity.IsValidContributor(); foreach (Comment c in requestPage.DataService.GetCommentsFor(entryId, allComments)) { SingleCommentView view = (SingleCommentView)LoadControl("SingleCommentView.ascx"); view.Comment = c; view.ObfuscateEmail = obfuscateEmail; commentViewContent.Controls.Add(view); } commentsClosed.Visible = false; commentViewTable.Visible = true; // only show the openid option when allowed in the config openIdTable.Visible = requestPage.SiteConfig.AllowOpenIdComments; commentsGravatarEnabled.Visible = requestPage.SiteConfig.CommentsAllowGravatar; // show the comments require approval warning when moderating, or suspected spam, // maybe users won't post multiple comments when their comment won't show immediately commentsModerated.Visible = (requestPage.SiteConfig.CommentsRequireApproval || potentialSpamSubmitted); if (potentialSpamSubmitted) { labelCommentsModerated.Text = resmgr.GetString("text_comment_potential_spam"); } // display no/some html labelCommentHtml.Visible = requestPage.SiteConfig.CommentsAllowHtml && (requestPage.SiteConfig.AllowedTags.AllowedTagsCount > 0); labelComment.Visible = !labelCommentHtml.Visible; labelCommentHtml.Text = String.Format(resmgr.GetString("text_comment_content_html"), requestPage.SiteConfig.AllowedTags.ToString()); if (SiteUtilities.AreCommentsAllowed(entry, requestPage.SiteConfig) == false) { commentsClosed.Visible = true; commentViewTable.Visible = false; openIdTable.Visible = false; // if comments are not allow, there is no need to show the approval warning commentsModerated.Visible = false; } if (Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "coCommentScript") == false && requestPage.SiteConfig.EnableCoComment == true) { string coCommentScript = String.Format(@" <script type=""text/javascript""> // this ensures coComment gets the correct values coco = {{ tool : ""dasBlog"", siteurl : ""{0}"", sitetitle : ""{1}"", pageurl : ""{2}"", pagetitle : ""{3}"", author : ""{4}"", formID : ""{5}"", textareaID : ""{6}"", buttonID : ""{7}"" }} </script> <script id=""cocomment-fetchlet"" src=""http://www.cocomment.com/js/enabler.js"" type=""text/javascript""> // this activates coComment </script> ", requestPage.SiteConfig.Root, Server.HtmlEncode(requestPage.SiteConfig.Title), Request.Url.ToString(), Server.HtmlEncode(entry.Title), Server.HtmlEncode(entry.Author), this.Page.Form.ClientID, this.comment.ClientID, this.add.ClientID ); Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "coComment", coCommentScript); } } }
private void ClickThroughsBox_PreRender(object sender, EventArgs e) { Control root = contentPlaceHolder; SiteConfig siteConfig = SiteConfig.GetSiteConfig(); ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext()); IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService); Dictionary <string, int> clickThroughUrls = new Dictionary <string, int>(); Dictionary <string, int> userAgents = new Dictionary <string, int>(); Dictionary <string, int> userDomains = new Dictionary <string, int>(); // get the user's local time DateTime utcTime = DateTime.UtcNow; DateTime localTime = siteConfig.GetConfiguredTimeZone().ToLocalTime(utcTime); if (Request.QueryString["date"] != null) { try { DateTime popUpTime = DateTime.ParseExact(Request.QueryString["date"], "yyyy-MM-dd", CultureInfo.InvariantCulture); utcTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, utcTime.Hour, utcTime.Minute, utcTime.Second); localTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, localTime.Hour, localTime.Minute, localTime.Second); } catch (FormatException ex) { ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, ex); } } LogDataItemCollection logItems = new LogDataItemCollection(); logItems.AddRange(logService.GetClickThroughsForDay(localTime)); if (siteConfig.AdjustDisplayTimeZone) { newtelligence.DasBlog.Util.WindowsTimeZone tz = siteConfig.GetConfiguredTimeZone(); TimeSpan ts = tz.GetUtcOffset(DateTime.UtcNow); int offset = ts.Hours; if (offset < 0) { logItems.AddRange(logService.GetClickThroughsForDay(localTime.AddDays(1))); } else { logItems.AddRange(logService.GetClickThroughsForDay(localTime.AddDays(-1))); } } foreach (LogDataItem log in logItems) { bool exclude = false; if (siteConfig.AdjustDisplayTimeZone) { if (siteConfig.GetConfiguredTimeZone().ToLocalTime(log.RequestedUtc).Date != localTime.Date) { exclude = true; } } if (!exclude) { string key = log.UrlRequested + "°" + log.UrlReferrer; if (!clickThroughUrls.ContainsKey(key)) { clickThroughUrls[key] = 0; } clickThroughUrls[key] = clickThroughUrls[key] + 1; if (!userAgents.ContainsKey(log.UserAgent)) { userAgents[log.UserAgent] = 0; } userAgents[log.UserAgent] = userAgents[log.UserAgent] + 1; if (!userDomains.ContainsKey(log.UserDomain)) { userDomains[log.UserDomain] = 0; } userDomains[log.UserDomain] = userDomains[log.UserDomain] + 1; } } root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(clickThroughUrls), resmgr.GetString("text_activity_click_throughs"), resmgr.GetString("text_activity_clicks"), new StatisticsBuilderCallback(this.BuildClickThroughsRow), dataService)); root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userDomains), resmgr.GetString("text_activity_user_domains"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildUserDomainRow), dataService)); root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userAgents), resmgr.GetString("text_activity_user_agent"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildAgentsRow), dataService)); DataBind(); }
private void ClickThroughsBox_PreRender(object sender, EventArgs e) { if (_robotDefinition == null) { return; } Control root = contentPlaceHolder; SiteConfig siteConfig = SiteConfig.GetSiteConfig(); ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext()); IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService); Dictionary <string, int> clickThroughUrls = new Dictionary <string, int>(); Dictionary <string, int> userAgents = new Dictionary <string, int>(); Dictionary <string, int> userDomains = new Dictionary <string, int>(); DateTime serverTimeUtc = DateTime.Now.ToUniversalTime(); DateTime localTime = siteConfig.GetConfiguredTimeZone().ToLocalTime(serverTimeUtc); if (Request.QueryString["date"] != null) { try { DateTime popUpTime = DateTime.ParseExact(Request.QueryString["date"], "yyyy-MM-dd", CultureInfo.InvariantCulture); localTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day); serverTimeUtc = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, 23, 59, 59).ToUniversalTime(); } catch (FormatException ex) { ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, ex); } } LogDataItemCollection logItems = new LogDataItemCollection(); logItems.AddRange(logService.GetClickThroughsForDay(serverTimeUtc)); // depending on the offset (positive or negative) we want to grab events in the // next or previos day to account for timezone difference. if (siteConfig.AdjustDisplayTimeZone) { newtelligence.DasBlog.Util.WindowsTimeZone tz = siteConfig.GetConfiguredTimeZone(); TimeSpan ts = tz.GetUtcOffset(DateTime.Now); int offset = ts.Hours; if (serverTimeUtc.Date != serverTimeUtc.AddHours(offset).Date) { logItems.AddRange(logService.GetClickThroughsForDay(serverTimeUtc.AddHours(offset))); } } foreach (LogDataItem log in logItems) { bool exclude = false; if (siteConfig.AdjustDisplayTimeZone) { if (siteConfig.GetConfiguredTimeZone().ToLocalTime(log.RequestedUtc).Date != localTime.Date) { exclude = true; } } if (_robotDefinition.IsRobot(log)) { exclude = true; } if (!exclude) { string key = log.UrlRequested + "°" + log.UrlReferrer; if (!clickThroughUrls.ContainsKey(key)) { clickThroughUrls[key] = 0; } clickThroughUrls[key] = clickThroughUrls[key] + 1; if (!userAgents.ContainsKey(log.UserAgent)) { userAgents[log.UserAgent] = 0; } userAgents[log.UserAgent] = userAgents[log.UserAgent] + 1; // AG User domain added. if (!userDomains.ContainsKey(log.UserDomain)) { userDomains[log.UserDomain] = 0; } userDomains[log.UserDomain] = userDomains[log.UserDomain] + 1; } } root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(clickThroughUrls), resmgr.GetString("text_activity_click_throughs"), resmgr.GetString("text_activity_clicks"), new StatisticsBuilderCallback(this.BuildClickThroughsRow), dataService)); root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userDomains), resmgr.GetString("text_activity_user_domains"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildUserDomainRow), dataService)); root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userAgents), resmgr.GetString("text_activity_user_agent"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildAgentsRow), dataService)); DataBind(); }
private void ReferrersBox_PreRender(object sender, EventArgs e) { Control root = contentPlaceHolder; SiteConfig siteConfig = SiteConfig.GetSiteConfig(); ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext()); string siteRoot = siteConfig.Root.ToUpper(); Dictionary <string, int> referrerUrls = new Dictionary <string, int>(); Dictionary <string, int> userAgents = new Dictionary <string, int>(); Dictionary <string, int> searchUrls = new Dictionary <string, int>(); Dictionary <string, int> userDomains = new Dictionary <string, int>(); // get the user's local time DateTime utcTime = DateTime.UtcNow; DateTime localTime = siteConfig.GetConfiguredTimeZone().ToLocalTime(utcTime); if (Request.QueryString["date"] != null) { try { DateTime popUpTime = DateTime.ParseExact(Request.QueryString["date"], "yyyy-MM-dd", CultureInfo.InvariantCulture); utcTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, utcTime.Hour, utcTime.Minute, utcTime.Second); localTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, localTime.Hour, localTime.Minute, localTime.Second); } catch (FormatException ex) { ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, ex); } } LogDataItemCollection logItems = new LogDataItemCollection(); logItems.AddRange(logService.GetReferralsForDay(localTime)); if (siteConfig.AdjustDisplayTimeZone) { newtelligence.DasBlog.Util.WindowsTimeZone tz = siteConfig.GetConfiguredTimeZone(); TimeSpan ts = tz.GetUtcOffset(DateTime.UtcNow); int offset = ts.Hours; if (offset < 0) { logItems.AddRange(logService.GetReferralsForDay(localTime.AddDays(1))); } else { logItems.AddRange(logService.GetReferralsForDay(localTime.AddDays(-1))); } } foreach (LogDataItem log in logItems) { bool exclude = false; if (log.UrlReferrer != null) { exclude = log.UrlReferrer.ToUpper().StartsWith(siteRoot); // Let Utils.ParseSearchString decide whether it's a search engine referrer. if (SiteUtilities.ParseSearchString(log.UrlReferrer) != null) { exclude = true; bool addToSearches = true; if (siteConfig.AdjustDisplayTimeZone) { if (siteConfig.GetConfiguredTimeZone().ToLocalTime(log.RequestedUtc).Date != localTime.Date) { addToSearches = false; } } if (addToSearches) { if (!searchUrls.ContainsKey(log.UrlReferrer)) { searchUrls[log.UrlReferrer] = 0; } searchUrls[log.UrlReferrer] = searchUrls[log.UrlReferrer] + 1; } } } if (siteConfig.AdjustDisplayTimeZone) { if (siteConfig.GetConfiguredTimeZone().ToLocalTime(log.RequestedUtc).Date != localTime.Date) { exclude = true; } } if (!exclude) { if (!referrerUrls.ContainsKey(log.UrlReferrer)) { referrerUrls[log.UrlReferrer] = 0; } referrerUrls[log.UrlReferrer] = referrerUrls[log.UrlReferrer] + 1; log.UserAgent = Server.HtmlEncode(log.UserAgent); if (!userAgents.ContainsKey(log.UserAgent)) { userAgents[log.UserAgent] = 0; } userAgents[log.UserAgent] = userAgents[log.UserAgent] + 1; if (!userDomains.ContainsKey(log.UserDomain)) { userDomains[log.UserDomain] = 0; } userDomains[log.UserDomain] = userDomains[log.UserDomain] + 1; } } Table rollupTable = new Table(); rollupTable.CssClass = "statsTableStyle"; TableRow row = new TableRow(); row.CssClass = "statsTableHeaderRowStyle"; row.Cells.Add(new TableCell()); row.Cells.Add(new TableCell()); row.Cells[0].CssClass = "statsTableHeaderColumnStyle"; row.Cells[1].CssClass = "statsTableHeaderNumColumnStyle"; row.Cells[0].Text = resmgr.GetString("text_activity_summary"); row.Cells[1].Text = resmgr.GetString("text_activity_hits"); rollupTable.Rows.Add(row); //SDH: I know this is gross, but I didn't want to totally rewrite this whole thing, I just wanted to get the rollup to work string total = String.Empty; Table internetSearchesTable = BuildStatisticsTable(GenerateSortedSearchStringItemList(searchUrls), resmgr.GetString("text_activity_internet_searches"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildSearchesRow), out total, null); BuildRow(total, rollupTable, resmgr.GetString("text_activity_internet_searches")); Table userDomainsTable = BuildStatisticsTable(GenerateSortedItemList(userDomains), resmgr.GetString("text_activity_user_domains"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildUserDomainRow), out total, null); Table userAgentsTable = BuildStatisticsTable(GenerateSortedItemList(userAgents), resmgr.GetString("text_activity_user_agent"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildAgentsRow), out total, null); Table referrerUrlsTable = BuildStatisticsTable(GenerateSortedItemList(referrerUrls), resmgr.GetString("text_activity_referrer_urls"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildReferrerRow), out total, null); BuildRow(total, rollupTable, resmgr.GetString("text_activity_referrer_urls")); root.Controls.Add(rollupTable); root.Controls.Add(internetSearchesTable); root.Controls.Add(referrerUrlsTable); root.Controls.Add(userDomainsTable); root.Controls.Add(userAgentsTable); //root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userAgents), CONSTUSERAGENTSLIST, CONSTHITS, new StatisticsBuilderCallback(this.BuildAgentsRow), out total, null)); DataBind(); }
private void EventlogBox_PreRender(object sender, EventArgs e) { SiteConfig siteConfig = SiteConfig.GetSiteConfig(); Control root = contentPlaceHolder; ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext()); Table table = new Table(); table.CssClass = "statsTableStyle"; TableRow row = new TableRow(); row.CssClass = "statsTableHeaderRowStyle"; row.Cells.Add(new TableCell()); row.Cells.Add(new TableCell()); row.Cells.Add(new TableCell()); row.Cells[0].CssClass = "statsTableDateColumnStyle"; row.Cells[1].CssClass = "statsTableNumColumnStyle"; row.Cells[2].CssClass = "statsTableColumnStyle"; row.Cells[0].Text = "<b>" + resmgr.GetString("text_time") + "</b>"; row.Cells[1].Text = "<b>" + resmgr.GetString("text_message_code") + "</b>"; row.Cells[2].Text = "<b>" + resmgr.GetString("text_message_text") + "</b>"; table.Rows.Add(row); // get the user's local time DateTime utcTime = DateTime.UtcNow; DateTime localTime = siteConfig.GetConfiguredTimeZone().ToLocalTime(utcTime); if (Request.QueryString["date"] != null) { try { DateTime popUpTime = DateTime.ParseExact(Request.QueryString["date"], "yyyy-MM-dd", CultureInfo.InvariantCulture); utcTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, utcTime.Hour, utcTime.Minute, utcTime.Second); localTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, localTime.Hour, localTime.Minute, localTime.Second); } catch (FormatException ex) { ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, ex); } } EventDataItemCollection logItems = new EventDataItemCollection(); logItems.AddRange(logService.GetEventsForDay(localTime)); if (siteConfig.AdjustDisplayTimeZone) { newtelligence.DasBlog.Util.WindowsTimeZone tz = siteConfig.GetConfiguredTimeZone(); TimeSpan ts = tz.GetUtcOffset(DateTime.UtcNow); int offset = ts.Hours; if (offset < 0) { logItems.AddRange(logService.GetEventsForDay(localTime.AddDays(1))); } else { logItems.AddRange(logService.GetEventsForDay(localTime.AddDays(-1))); } } EventDataItem[] sortedLogItems = logItems.ToSortedArray(); foreach (EventDataItem eventItem in sortedLogItems) { if (siteConfig.AdjustDisplayTimeZone) { if (siteConfig.GetConfiguredTimeZone().ToLocalTime(eventItem.EventTimeUtc).Date != localTime.Date) { continue; } } row = new TableRow(); row.CssClass = "statsTableRowStyle"; switch (eventItem.EventCode) { case ((int)EventCodes.Error): case ((int)EventCodes.PingbackServerError): case ((int)EventCodes.PingWeblogsError): case ((int)EventCodes.Pop3ServerError): case ((int)EventCodes.SmtpError): row.CssClass = "statsTableRowStyleError"; break; case ((int)EventCodes.SecurityFailure): row.CssClass = "statsTableRowStyleSecurityFailure"; break; case ((int)EventCodes.TrackbackBlocked): case ((int)EventCodes.ReferralBlocked): case ((int)EventCodes.ItemReferralBlocked): case ((int)EventCodes.CommentBlocked): case ((int)EventCodes.PingbackBlocked): row.CssClass = "statsTableRowStyleBlocked"; break; default: break; } row.Cells.Add(new TableCell()); row.Cells.Add(new TableCell()); row.Cells.Add(new TableCell()); row.Cells[0].CssClass = "statsTableDateColumnStyle"; row.Cells[1].CssClass = "statsTableNumColumnStyle"; row.Cells[2].CssClass = "statsTableColumnStyle"; if (siteConfig.AdjustDisplayTimeZone) { row.Cells[0].Text = siteConfig.GetConfiguredTimeZone().ToLocalTime(eventItem.EventTimeUtc).ToString("yyyy-MM-dd HH:mm:ss tt"); } else { row.Cells[0].Text = eventItem.EventTimeUtc.ToString("yyyy-MM-dd HH:mm:ss tt") + " UTC"; } row.Cells[1].Text = eventItem.EventCode.ToString(); row.Cells[2].Text = eventItem.HtmlMessage; table.Rows.Add(row); } root.Controls.Add(table); DataBind(); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); resmgr = ApplicationResourceTable.Get(); if (!Page.IsPostBack) { DateTime dt = new DateTime(DateTime.Now.Year, 1, 1); DateTime filteredDate = DateTime.UtcNow; string date = null; if (this.Request.QueryString["date"] != null) { date = this.Request.QueryString["date"]; try { filteredDate = DateTime.ParseExact(date, "yyyy-MM-dd", CultureInfo.InvariantCulture); } catch (FormatException ex) { ErrorTrace.Trace(TraceLevel.Error, ex); } } // move the local/non-local date logic to one place if (((SharedBasePage)Page).SiteConfig.AdjustDisplayTimeZone && date == null) { newtelligence.DasBlog.Util.WindowsTimeZone tz = ((SharedBasePage)Page).SiteConfig.GetConfiguredTimeZone(); filteredDate = tz.ToLocalTime(filteredDate); } // someone is trying to mess with us, let's play along if (filteredDate.Year > dt.Year || filteredDate.Year < dt.Year - 11) { dt = new DateTime(filteredDate.Year, 1, 1); } for (int i = 0; i > -12; i--) { this.DropDownListYear.Items.Add(dt.AddYears(i).ToString("yyyy")); } try{ this.DropDownListYear.SelectedValue = filteredDate.Year.ToString(); }catch (ArgumentOutOfRangeException) { //.. tried to set a year in the future, that's not in the list. } for (int i = 0; i < 12; i++) { this.DropDownListMonth.Items.Add(dt.AddMonths(i).ToString("MMMM")); } this.DropDownListMonth.SelectedIndex = filteredDate.Month - 1; int numDays = DateTime.DaysInMonth(Convert.ToInt32(this.DropDownListYear.SelectedItem.Text), this.DropDownListMonth.SelectedIndex + 1); for (int i = 1; i <= numDays; i++) { this.DropDownListDay.Items.Add(i.ToString()); } this.DropDownListDay.SelectedIndex = filteredDate.Day - 1; // set the href for for the links DateTime nextDate = filteredDate.AddDays(1); DateTime previousDate = filteredDate.AddDays(-1); DateTime today = DateTime.Now; string requestUrl = this.Context.Request.Path; string dateFormat = "{0}?date={1:yyyy-MM-dd}"; this.linkNext.HRef = String.Format(System.Globalization.CultureInfo.InvariantCulture, dateFormat, requestUrl, nextDate); this.linkPrevious.HRef = String.Format(System.Globalization.CultureInfo.InvariantCulture, dateFormat, requestUrl, previousDate); this.linkToday.HRef = String.Format(System.Globalization.CultureInfo.InvariantCulture, dateFormat, requestUrl, today); } DataBind(); }