views:

30

answers:

1

In the Page_Load event I would like to have the current week selected on the calendar instead of just the current day. How can this be done?

<asp:Calendar 
ID="Calendar1" 
runat="server" 
ondayrender="Calendar1_DayRender"   
SelectionMode="DayWeek" 
onselectionchanged="Calendar1_SelectionChanged">
</asp:Calendar>


        protected void Page_Load(object sender, EventArgs e)
    {

       Calendar1.SelectedDate = System.DateTime.Today;

    }

    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        e.Day.IsSelectable = false;
    }
A: 

Hi Joshua

Give this a try:

Calendar1.SelectionMode = CalendarSelectionMode.DayWeek;  
ArrayList selectedDates = new ArrayList();  
DateTime today = DateTime.Now;    
DateTime firstDay = today.AddDays(-(double)(today.DayOfWeek));    
for (int loop = 0; loop < 7; loop++)    
    Calendar1.SelectedDates.Add(firstDay.AddDays(loop));   
Ritik Khatwani
perfect thank you
Joshua Slocum