Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
Dim adoDATA As New DataTable
adoDATA = clsDB.GetDT("SELECT * FROM MST_Activity WHERE ShowPrivate='N' AND ShowIndex='Y'")
For i As Integer = 0 To adoDATA.Rows.Count - 1
If e.Day.Date = Format(adoDATA.Rows(i).Item("ActDate"), "dd/MM/yyyy") Then
e.Cell.BackColor = System.Drawing.Color.Red
e.Cell.BorderColor = System.Drawing.Color.Gray
e.Cell.BorderWidth = 1
End If
Next
End Sub
จาก code นี้ใน DB ผมเก็บวันที่ของกิจกรรมวันเดียวคือ ActDate มันทำได้ครับ
Dim starDate As Date = DateAdd(DateInterval.Month, -1, Now)
Dim endDate As Date = DateAdd(DateInterval.Year, 1, Now)
Dim strsql As String
strsql = "SELECT * FROM MST_Activity "
strsql += "WHERE ActDate BETWEEN '" & CDate(Format(starDate, "yyyy-MM-01")) & "' AND '" & CDate(Format(endDate, "yyyy-12-31")) & "' "
strsql += "AND ShowPrivate='N' AND ShowIndex='Y'"
strsql += " ORDER BY ActDate"
Dim starDate As Date = DateAdd(DateInterval.Month, -1, Now)
Dim endDate As Date = DateAdd(DateInterval.Year, 1, Now)
Dim strsql As String
strsql = "SELECT * FROM MST_Activity "
strsql += "WHERE ActDate BETWEEN '" & CDate(Format(starDate, "yyyy-MM-01")) & "' AND '" & CDate(Format(endDate, "yyyy-12-31")) & "' "
strsql += "AND ShowPrivate='N' AND ShowIndex='Y'"
strsql += " ORDER BY ActDate"