2009-12-06 48 views
0

每當客戶端在日曆控件上選擇日期時,我將添加到服務器上的DateTime對象列表中,然後突出顯示控件上的所有選定日期。我可以突出顯示在頁面加載列表中實例化的日期以及客戶端選擇的第一個日期。然而,在控件上進一步的日期選擇只是改變哪個日期被突出顯示,即。不突出更多。客戶端在運行時填充服務器集合

我已經通過在選擇在運行時將所選擇的DateTime對象列表,然後將他們每個人的日曆「選擇日期」,認爲房地產會得到解決的日曆控件結算上選擇SelectedDates財產的問題一個新的日期。通過打印日期列表中的所有日期進行調試通過文本框顯示列表實例化的日期,最新的選擇僅在列表中,而不是先前的選擇。我的問題和我認爲的問題, 服務器上的列表可以在運行時由客戶端的操作填充,並添加到? 我在VS2008上使用ASP和C#.Net3.5。 謝謝

我的代碼 System.Collections.Generic.List dates;

protected void Page_Load(object sender, EventArgs e) { 
     this.dates = new List<DateTime>(); 
     this.dates.Add(new DateTime(2009,12,2)); 
     this.dates.Add(new DateTime(2009, 12, 3)); 
     this.dates.Add(new DateTime(2009, 12, 16)); 
     fillDates(); 
    } 

    protected void AvailCalender_SelectionChanged(object sender, EventArgs e){ 
     this.dates.Add(this.AvailCalender.SelectedDate); 
     foreach (DateTime date in this.dates) 
     { 
      this.AvailCalender.SelectedDates.Add(date); 
      this.displayText.Text = this.displayText.Text + date.ToShortDateString(); 
     } 
     fillDates(); 
    } 


    protected void fillDates() 
    { 
     foreach (DateTime dates in this.dates) 
     { 
      this.AvailCalender.SelectedDates.Add(dates); 
     } 
     this.AvailCalender.SelectedDayStyle.BackColor = System.Drawing.Color.Blue; 
    } 

回答

0

List<DateTime>正在創建每個回發,因此它不保存以前的選擇。您需要以某種方式堅持它,例如使用ViewState,Session或將其存儲在數據庫中。只有在第一次使用Page.IsPostBack來檢查這是否是該頁面第一次被擊中時才創建。

相關問題