2011-06-23 52 views
0

我有一個我用作時間跟蹤器的asp.net日曆。目前,我有一個MySQL查詢填充日曆與所需的信息,但我不知道如何檢索這些信息時選擇其中一天。當用戶選擇日期時,我想從日期中獲取信息並填入一對標籤。日曆代碼如下。謝謝。在asp.net中使用超鏈接日曆

 If Not dsDate Is Nothing Then 
     For Each dr As DataRow In dsDate.Tables(0).Rows 
      description = CType(dr("Description"), String) 
      nextDate = CType(dr("Date"), DateTime) 
      hours = CType(dr("Hours"), Integer) 
      If nextDate = e.Day.Date And description = "Sick" Then 
       e.Cell.BackColor = System.Drawing.Color.DarkGreen 
       e.Cell.ToolTip = description & " - " & hours & " Hours" 
      ElseIf nextDate = e.Day.Date And description = "Vacation" Then 
       e.Cell.BackColor = System.Drawing.Color.Brown 
       e.Cell.ToolTip = description & " - " & hours & " Hours" 
      End If 
     Next 
    End If 
    If e.Day.IsWeekend Then 
     e.Cell.BackColor = System.Drawing.Color.LightSkyBlue 
     e.Day.IsSelectable = False 
    End If 
    If nottouched And Not e.Day.IsWeekend And Not e.Cell.BackColor = System.Drawing.Color.DarkGreen And Not e.Day.IsOtherMonth And Not e.Cell.BackColor = System.Drawing.Color.Brown Then 
     e.Cell.Attributes.Add("onmouseover", onmouseoverStyle) 
     e.Cell.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", rowBackColor)) 
    End If 
+0

你的確切意思是'從日期獲取信息',你是否想要自己選定的日期? – R3D3vil

+0

我希望將選定的日期和我添加到該日期的工具提示中的信息添加到頁面上的幾個標籤上。或者,如果它更容易,當點擊一個日期時,我想運行一個針對mysql的查詢來填充標籤。 基本上,我不知道日期點擊時發生了什麼!我是新來的這個東西。 –

回答

0

下面的代碼填充在C#選定日期的標籤:

monthCalendar1.MaxSelectionCount = 1;
label1.Text = monthCalendar1.SelectionRange.Start.ToShortDateString();

現在您可以根據此日期運行查詢並嘗試獲取其他值。

+0

我在這個上面跳了槍。我對maxselectioncount或選擇範圍沒有任何選擇。 我相信我在正確的軌道上: selecteddate = Calendar1.SelectedDate.ToString() query =「選擇日期,描述,小時來自度假凡login ='username'和Where Date ='」&selecteddate &「'」 問題在於,我在dayrender事件中執行此操作,因此selecteddate會在日曆加載時的每個月的每一天執行。 –