Reputation: 24332
I am displaying calendar using calendar control.
Each date is displayed as Link button.
But i want only last 30 days(dates) from current date, to be enabled for client click. on those days i will write some code on SelectionChanged event. But goal is other dates must be disabled for click.
They should not have link button.
Upvotes: 0
Views: 492
Reputation: 38428
Try to write custom day rendering function and attach it to DayRender
event of your Calendar control. It should be pretty simple.
<asp:Calendar ID="C1" runat="server" OnDayRender="Calendar1_DayRender" />
private void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date < BeginningOfDateRange ||
e.Day.Date > EndOfDateRange)
{
e.Cell.BackColor = System.Drawing.Color.LightGray
e.Day.IsSelectable = False
}
}
Upvotes: 1
Reputation: 96606
You can handle the DayRender event of the calendar control to customize the appearance of each day displayed. This event handler is called for each day displayed by the calendar control:
<asp:Calendar ID="Calendar1" runat="server" OnDayRender="Calendar1_DayRender">
</asp:Calendar>
And in the code-behind:
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
e.Day.IsSelectable = IsDateValid(e.Day.Date);
}
Where IsDateValid() is a method you implement to check whether a date should be enabled or not.
Upvotes: 1