Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 134869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:41:29+00:00 2026-05-11T06:41:29+00:00

Sometimes when displaying a calendar it is necessary to prevent the weekend days and

  • 0

Sometimes when displaying a calendar it is necessary to prevent the weekend days and the weekend names in the day header from showing, is there a way to do this using the ASP.NET Calendar control?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:41:30+00:00Added an answer on May 11, 2026 at 6:41 am

    As the control is provided, there is no way to do this without overriding the control. One way of doing this is to is to override the OnDayRender and Render methods to remove the information from the output prior to sending it back to the client.

    The following is a screen shot of what the control looks like when rendered:

    Example of weekday calendar

    The following is a basic control override that demonstrates removing the weekend day columns from the control.

    /*------------------------------------------------------------------------------  * Author - Rob (http://stackoverflow.com/users/1185/rob)  * -----------------------------------------------------------------------------  * Notes  * - This might not be the best way of doing things, so you should test it  *   before using it in production code.  * - This control was inspired by Mike Ellison's article on The Code Project  *   found here: http://www.codeproject.com/aspnet/MellDataCalendar.asp  * ---------------------------------------------------------------------------*/ using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Text; using System.IO; using System.Xml;  namespace DataControls {     /// <summary>     /// Example of a ASP.NET Calendar control that has been overriden to force     /// the weekend columns to be hidden on demand.     /// </summary>     public class DataCalendar : Calendar     {         private bool _hideWeekend;         private int _saturday;         private int _sunday;          /// <summary>Constructor</summary>         public DataCalendar()             : base()         {             // Default to showing the weekend             this._hideWeekend = false;             // Set the default values for Saturday and Sunday             this.Saturday = 6;             this.Sunday = 0;         }          /// <summary>         /// Indicate if the weekend days should be shown or not, set to true         /// if the weekend should be hidden, false otherwise. This field          /// defaults to false.         /// </summary>         public bool HideWeekend         {             get { return this._hideWeekend; }             set { this._hideWeekend = value; }         }          /// <summary>         /// Override the default index for Saturdays.         /// </summary>         /// <remarks>This option is provided for internationalization options.</remarks>         public int Saturday          {             get { return this._saturday; }             set { this._saturday = value; }         }           /// <summary>         /// Override the default index for Sundays.         /// </summary>         /// <remarks>This option is provided for internationalization options.</remarks>         public int Sunday          {             get { return this._sunday; }             set { this._sunday = value; }         }          /// <summary>         /// Render the day on the calendar with the information provided.         /// </summary>         /// <param name='cell'>The cell in the table.</param>         /// <param name='day'>The calendar day information</param>         protected override void OnDayRender(TableCell cell, CalendarDay day)         {             // If this is a weekend day and they should be hidden, remove             // them from the output             if (day.IsWeekend && this._hideWeekend)             {                 day = null;                 cell.Visible = false;                 cell.Text = string.Empty;             }             // Call the base render method too             base.OnDayRender(cell, day);         }          /// <summary>         /// Render the calendar to the HTML stream provided.         /// </summary>         /// <param name='html'>The output control stream to write to.</param>         protected override void Render(HtmlTextWriter html)         {             // Setup a new HtmlTextWriter that the base class will use to render             StringBuilder sb = new StringBuilder();             StringWriter sw = new StringWriter(sb);             HtmlTextWriter calendar = new HtmlTextWriter(sw);             // Call the base Calendar's Render method allowing OnDayRender()              // to be executed.             base.Render(calendar);             // Check to see if we need to remove the weekends from the header,             // if we do, then remove the fields and use the new verison for             // the output. Otherwise, just use what was previously generated.             if (this._hideWeekend && this.ShowDayHeader)             {                 // Load the XHTML to a XML document for processing                 XmlDocument xml = new XmlDocument();                 xml.Load(new StringReader(sw.ToString()));                 // The Calendar control renders as a table, so navigate to the                 // second TR which has the day headers.                 XmlElement root = xml.DocumentElement;                 XmlNode oldNode = root.SelectNodes('/table/tr')[1];                 XmlNode sundayNode = oldNode.ChildNodes[this.Sunday];                 XmlNode saturdayNode = oldNode.ChildNodes[this.Saturday];                 XmlNode newNode = oldNode;                 newNode.RemoveChild(sundayNode);                 newNode.RemoveChild(saturdayNode);                 root.ReplaceChild(oldNode, newNode);                 // Replace the buffer                 html.WriteLine(root.OuterXml);             }             else             {                 html.WriteLine(sw.ToString());             }         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there way to speed up displaying a lot of text in a winforms
Sometimes R stops displaying output. I type the number 1, followed by the return
I'm displaying articles on a page. The article titles sometimes spill over onto two
for examle <app:CustomDropDown ID=test runat=server InvalidProperty=SOMETHING /> This does not generate an error. Sometimes
I am using CreateDIBSection() to create a HBITMAP from a buffer, but sometimes -
I am pulling values submitted from a form and displaying them in a couple
I have a web page displaying data using dojo datagrid. Sometimes, users need to
I have a problem with displaying data from mysql database. My client requires to
Basically I'm getting some data from a service and displaying the results in a
i am displaying remote images on my service <img src=http://remote-site.com/imageX> However, sometimes the image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.