本文介绍了不明智地分割一周的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想每年不分割一周.例如,如果2006年有52周,它将显示1到52.如果2007年又有53周,它将像这样拆分1到53.
现在,我将显示所有星期,不对差异进行拆分.年.
代码如下.
--------------
Hi,
I want to split the week no year wise. for example if 2006 has 52 weeks it will display 1 to 52. if 2007 has 53 weeks again it will split 1 to 53 like that.
now, i am displaying all the weeks without split for the diff. year.
Code is below.
--------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'' Assumes that week range is from Sunday - Saturday
Dim FromYr As Integer = "2006"
Dim ToYear As Integer = "2015"
Dim firstDayOfYear As New DateTime(FromYr, 1, 1)
Dim lastDayOfYear As New DateTime(ToYear, 12, 31)
Dim weekNumber As Integer = 0
Dim weekList As New List(Of String)()
Dim tempDate As DateTime = firstDayOfYear
Dim tempString As String = String.Empty
While tempDate <= lastDayOfYear
weekNumber += 1
tempString = weekNumber.ToString() & " | "
tempString += tempDate.ToShortDateString() & " - "
tempDate = GetLastDayOfWeek(tempDate, lastDayOfYear)
tempString += tempDate.ToShortDateString()
weekList.Add(tempString)
tempDate = tempDate.AddDays(1)
End While
drpWeeknos.DataSource = weekList
drpWeeknos.DataBind()
End Sub
Private Function GetLastDayOfWeek(ByVal firstDayOfWeek As DateTime, ByVal lastDayOfYear As DateTime) As DateTime
Dim lastDayOfWeek As DateTime = firstDayOfWeek
If firstDayOfWeek.DayOfWeek = DayOfWeek.Monday Then
lastDayOfWeek = firstDayOfWeek.AddDays(6)
End If
If firstDayOfWeek.DayOfWeek = DayOfWeek.Tuesday Then
lastDayOfWeek = firstDayOfWeek.AddDays(5)
End If
If firstDayOfWeek.DayOfWeek = DayOfWeek.Wednesday Then
lastDayOfWeek = firstDayOfWeek.AddDays(4)
End If
If firstDayOfWeek.DayOfWeek = DayOfWeek.Thursday Then
lastDayOfWeek = firstDayOfWeek.AddDays(3)
End If
If firstDayOfWeek.DayOfWeek = DayOfWeek.Friday Then
lastDayOfWeek = firstDayOfWeek.AddDays(2)
End If
If firstDayOfWeek.DayOfWeek = DayOfWeek.Saturday Then
lastDayOfWeek = firstDayOfWeek.AddDays(1)
End If
If firstDayOfWeek.DayOfWeek = DayOfWeek.Sunday Then
lastDayOfWeek = firstDayOfWeek
End If
If lastDayOfWeek > lastDayOfYear Then
lastDayOfWeek = lastDayOfYear
End If
Return lastDayOfWeek
End Function
请帮助.下拉列表显示为每年都不明智.
问候,
Ganesh.S
Pls. help. Dropdown display as week no wise for every year.
Regards,
Ganesh.S
推荐答案
这篇关于不明智地分割一周的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!