Problem med Uge nr. til Asp.Calendar
HejJeg har denne code som viser uge nr. for hver uge.
Den viser dem rigtigt, men hvis jeg finder en uge med 53 uger så laver den uge 53 til uge 0.
Og så viser den af og til en uge for meget når jeg kigger på en måned.
Kan nogle hjælpe mig, med flg.
- Uge 0 = uge 53.
- Vis kun de uger der er relevant for en måned.
- Dage fra tidligere/fremtidige måned, men som er i en uge der er relevant for denne måned skal slørres.
Håber i kan hjælpe.
Main Kode
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="calendar_week_no.aspx.vb" Inherits="calendar_week_no" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server" OnDayRender="Calendar1_DayRender" SelectionMode="DayWeek" SelectWeekText="">
</asp:Calendar>
</div>
</form>
</body>
</html>
Code_Behind
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Partial Class calendar_week_no
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Sub Calendar1_DayRender(sender As Object, e As DayRenderEventArgs)
If e.Day.[Date].DayOfWeek = DayOfWeek.Sunday Then
Dim WeekNumber As New Label()
' This is a crude approximation
Dim DayAmount As Integer = DateDiff("d", "1.1." & Year(e.Day.Date), DateAdd("d", 1, e.Day.Date))
Dim ThisWeek As Integer
Dim wkd As Integer = Weekday("1.1." & Year(e.Day.Date))
ThisWeek = DayAmount / 7
WeekNumber.Text = ThisWeek.ToString()
' move the label to the left, outside the sunday cell, into the selector cell
WeekNumber.Style.Add("left", "10px")
WeekNumber.Style.Add("position", "absolute")
e.Cell.Controls.Add(WeekNumber)
End If
End Sub
End Class