Calendar control - disabling past dates.

Discussion in 'ASP .Net' started by Greg Smith, Aug 14, 2006.

  1. Greg Smith

    Greg Smith Guest

    Is there a way to disable past dates for a calendar control, or individual
    date for that matter?


    Any help is greatly appreciated.
     
    Greg Smith, Aug 14, 2006
    #1
    1. Advertising

  2. Greg Smith

    Mark Rae Guest

    "Greg Smith" <> wrote in message
    news:e$tn$...

    > Is there a way to disable past dates for a calendar control, or individual
    > date for that matter?


    Dead easy - you need the DayRender method for this.

    In your HTML:

    <asp:Calendar ID="MyCalendar" runat="server"
    OnDayRender="MyCalendar_DayRender" />


    And in your code-behind:

    protected void cal_DayRender(object source, DayRenderEventArgs e)
    {
    if (e.Day.Date.Day == 18)
    {
    e.Cell.Controls.Clear();
    e.Cell.Text = e.Day.DayNumberText;
    e.Cell.BackColor = System.Drawing.Color.Gainsboro;
    }
    }

    That will disable the 18th of every month. I'm sure you can figure the rest
    out from that...
     
    Mark Rae, Aug 14, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    903
    Rob Schieber
    Sep 30, 2005
  2. Greg Smith

    Calendar control - disabling past dates.

    Greg Smith, Aug 14, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    151
    Nathan Sokalski
    Aug 16, 2006
  3. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    230
    Mark Schupp
    Aug 9, 2004
  4. Dale
    Replies:
    4
    Views:
    118
  5. Replies:
    1
    Views:
    89
    Grehom
    Jun 16, 2008
Loading...

Share This Page