asp.net3.5 csharp Calendar 控件显示周次
javascript代码
1 <script type="text/javascript">
2 function addWkColumn(tblId, wkStart)
3 {
4 var tbl = document.getElementById(tblId);
5
6 var tblBodyObj = tbl.tBodies[0];
7 for (var i=0; i<tblBodyObj.rows.length; i++)
8 {
9 // Month Header
10 if (i==0)
11 {
12 // Add extra colspan column
13 tblBodyObj.rows[i].cells[0].colSpan=8;
14 }
15 // Week Header
16 if (i==1)
17 {
18 // Add week column headline
19 var newCell = tblBodyObj.rows[i].insertCell(0);
20 newCell.innerHTML = 'wk';
21 newCell.style.fontSize= '8px';
22 newCell.style.fontWeight= 'bold';
23 newCell.style.verticalAlign= 'bottom';
24 newCell.style.backgroundColor = '#ffffee';
25 }
26
27 // Normal row
28 if (i >= 2 )
29 {
30 // Add the weeknumbers
31 var newCell = tblBodyObj.rows[i].insertCell(0);
32 if (tblBodyObj.rows[i].cells[1].style.color != 'white' || tblBodyObj.rows[i].cells[2].style.color != 'white' || tblBodyObj.rows[i].cells[3].style.color != 'white' || tblBodyObj.rows[i].cells[4].style.color != 'white' || tblBodyObj.rows[i].cells[5].style.color != 'white' || tblBodyObj.rows[i].cells[6].style.color != 'white' || tblBodyObj.rows[i].cells[7].style.color != 'white' )
33 {
34 newCell.innerHTML = wkStart;
35 wkStart += 1;
36 }
37 newCell.style.fontSize= '8px';
38 newCell.style.backgroundColor = '#ffffee';
39 }
40 }
41 }
42
43 </script>
2 function addWkColumn(tblId, wkStart)
3 {
4 var tbl = document.getElementById(tblId);
5
6 var tblBodyObj = tbl.tBodies[0];
7 for (var i=0; i<tblBodyObj.rows.length; i++)
8 {
9 // Month Header
10 if (i==0)
11 {
12 // Add extra colspan column
13 tblBodyObj.rows[i].cells[0].colSpan=8;
14 }
15 // Week Header
16 if (i==1)
17 {
18 // Add week column headline
19 var newCell = tblBodyObj.rows[i].insertCell(0);
20 newCell.innerHTML = 'wk';
21 newCell.style.fontSize= '8px';
22 newCell.style.fontWeight= 'bold';
23 newCell.style.verticalAlign= 'bottom';
24 newCell.style.backgroundColor = '#ffffee';
25 }
26
27 // Normal row
28 if (i >= 2 )
29 {
30 // Add the weeknumbers
31 var newCell = tblBodyObj.rows[i].insertCell(0);
32 if (tblBodyObj.rows[i].cells[1].style.color != 'white' || tblBodyObj.rows[i].cells[2].style.color != 'white' || tblBodyObj.rows[i].cells[3].style.color != 'white' || tblBodyObj.rows[i].cells[4].style.color != 'white' || tblBodyObj.rows[i].cells[5].style.color != 'white' || tblBodyObj.rows[i].cells[6].style.color != 'white' || tblBodyObj.rows[i].cells[7].style.color != 'white' )
33 {
34 newCell.innerHTML = wkStart;
35 wkStart += 1;
36 }
37 newCell.style.fontSize= '8px';
38 newCell.style.backgroundColor = '#ffffee';
39 }
40 }
41 }
42
43 </script>
C#代码
csharp 代码
1 //涂聚文注:在1月份的周次显示出显问题,请能纠正过来修改,谢谢
2 protected void Page_Load(object sender, EventArgs e)
3 {
4 HtmlHead head = (HtmlHead)Page.Header;
5 this.Calendar1.ToolTip = "缔友计算机信息技术有限有公司日历";
6
7 Page.Header.Title = "缔友计算机信息技术有限有公司日历--显示周次";
8 HtmlMeta meta = new HtmlMeta();
9 meta.Name = "Author";
10 meta.Attributes.Add("Content ", "geovindu");
11 head.Controls.AddAt(1, meta);
12
13 HtmlMeta key = new HtmlMeta();
14 key.Name = "keywords";
15 key.Attributes.Add("Content ", "Geovin Du");
16 head.Controls.AddAt(2, key);
17
18 HtmlLink ico = new HtmlLink();
19 ico.Href = "~/favicon.ico";
20 ico.Attributes.Add("rel", "icon");
21 ico.Attributes.Add("type", "image/ico");
22 head.Controls.AddAt(3, ico);
23
24
25 HtmlLink bookmark = new HtmlLink();
26 bookmark.Href = "~/favicon.ico";
27 bookmark.Attributes.Add("rel", "bookmark");
28 //bookmark.Attributes.Add("type", "image/ico");
29 head.Controls.AddAt(4, bookmark);
30
31 HtmlLink shortcut = new HtmlLink();
32 shortcut.Href = "~/favicon.ico";
33 shortcut.Attributes.Add("rel", "shortcut icon");
34 shortcut.Attributes.Add("type", "image/x-icon");
35 head.Controls.AddAt(5, shortcut);
36
37 HtmlMeta description = new HtmlMeta();
38 description.Name = "description";
39 description.Attributes.Add("Content ", "涂聚文,缔友计算机信息技术有限公司,经营信息流,物流,人力资源流,资本流的系统解决方案的开发与设计和服务");
40 head.Controls.AddAt(6, description);
41 int i=getISOWeek(DateTime.Today);
42 Response.Write(i.ToString()+"weeks");
43 Response.Write(Calendar1.TodaysDate.ToShortDateString());
44
45 }
46 /// <summary>
47 /// 添加周列
48 /// </summary>
49 /// <param name="curMonth"></param>
50 private void addWeekNumberColumn(DateTime curMonth)//
51 {
52 string jscript;
53 //DateTime curMonth = Convert.ToDateTime(Calendar1.VisibleDate.Year.ToString() + "-" + Calendar1.VisibleDate.Month.ToString() + "-01");
Get the date shown in the calendar control
54 // curMonth = Calendar1.VisibleDate;
55
56 // Find first day of the current month
57 // 58
59 // Build javascript
60 // if (curMonth.Month == 1 && curMonth.Day == 1)
61 // {
62 // int w = 1;
63 // jscript = @"<script type='text/javascript'>
64 // addWkColumn('" + Calendar1.ClientID + "', " + w.ToString() + @");
65 // </script>";
66 // }
67 jscript = @"<script type='text/javascript'>
68 addWkColumn('" + Calendar1.ClientID + "', " + getISOWeek(curMonth).ToString() + @");
69 </script>";
70
71 // Add script to page for execution of addWkColumn javascript function
72 Page.ClientScript.RegisterStartupScript(this.GetType(), "AddWeeknumbers", jscript);
73 }
74
75 /// <summary>
76 /// 获取几周
77 /// </summary>
78 /// <param name="day"></param>
79 /// <returns></returns>
80 private int getISOWeek(DateTime day)
81 {
82 return System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(day, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
83 }
84
85
86 protected void Calendar1_PreRender(object sender, EventArgs e)
87 {
88 if (Calendar1.VisibleDate.Year == 1 && Calendar1.VisibleDate.Month == 1)
89 {
90 // Add weeknumbers
91 DateTime curMonth = Calendar1.TodaysDate;
92 Calendar1.VisibleDate = new DateTime(curMonth.Year, curMonth.Month, 1);
93 addWeekNumberColumn(Calendar1.VisibleDate);
94 }
95 if (Calendar1.VisibleDate.Month == 1)
96 {
97 //DateTime curMonth;
98 Calendar1.VisibleDate = new DateTime(Calendar1.VisibleDate.Year, 1, 1);
99 addWeekNumberColumn(Calendar1.VisibleDate);
100 }
101 Calendar1.VisibleDate = new DateTime(Calendar1.VisibleDate.Year, Calendar1.VisibleDate.Month, 1);
102
103 addWeekNumberColumn(Calendar1.VisibleDate);
104
105 int i = getISOWeek(Calendar1.VisibleDate);
106 Response.Write(i.ToString() + "weeks");
107 }
2 protected void Page_Load(object sender, EventArgs e)
3 {
4 HtmlHead head = (HtmlHead)Page.Header;
5 this.Calendar1.ToolTip = "缔友计算机信息技术有限有公司日历";
6
7 Page.Header.Title = "缔友计算机信息技术有限有公司日历--显示周次";
8 HtmlMeta meta = new HtmlMeta();
9 meta.Name = "Author";
10 meta.Attributes.Add("Content ", "geovindu");
11 head.Controls.AddAt(1, meta);
12
13 HtmlMeta key = new HtmlMeta();
14 key.Name = "keywords";
15 key.Attributes.Add("Content ", "Geovin Du");
16 head.Controls.AddAt(2, key);
17
18 HtmlLink ico = new HtmlLink();
19 ico.Href = "~/favicon.ico";
20 ico.Attributes.Add("rel", "icon");
21 ico.Attributes.Add("type", "image/ico");
22 head.Controls.AddAt(3, ico);
23
24
25 HtmlLink bookmark = new HtmlLink();
26 bookmark.Href = "~/favicon.ico";
27 bookmark.Attributes.Add("rel", "bookmark");
28 //bookmark.Attributes.Add("type", "image/ico");
29 head.Controls.AddAt(4, bookmark);
30
31 HtmlLink shortcut = new HtmlLink();
32 shortcut.Href = "~/favicon.ico";
33 shortcut.Attributes.Add("rel", "shortcut icon");
34 shortcut.Attributes.Add("type", "image/x-icon");
35 head.Controls.AddAt(5, shortcut);
36
37 HtmlMeta description = new HtmlMeta();
38 description.Name = "description";
39 description.Attributes.Add("Content ", "涂聚文,缔友计算机信息技术有限公司,经营信息流,物流,人力资源流,资本流的系统解决方案的开发与设计和服务");
40 head.Controls.AddAt(6, description);
41 int i=getISOWeek(DateTime.Today);
42 Response.Write(i.ToString()+"weeks");
43 Response.Write(Calendar1.TodaysDate.ToShortDateString());
44
45 }
46 /// <summary>
47 /// 添加周列
48 /// </summary>
49 /// <param name="curMonth"></param>
50 private void addWeekNumberColumn(DateTime curMonth)//
51 {
52 string jscript;
53 //DateTime curMonth = Convert.ToDateTime(Calendar1.VisibleDate.Year.ToString() + "-" + Calendar1.VisibleDate.Month.ToString() + "-01");
Get the date shown in the calendar control
54 // curMonth = Calendar1.VisibleDate;
55
56 // Find first day of the current month
57 // 58
59 // Build javascript
60 // if (curMonth.Month == 1 && curMonth.Day == 1)
61 // {
62 // int w = 1;
63 // jscript = @"<script type='text/javascript'>
64 // addWkColumn('" + Calendar1.ClientID + "', " + w.ToString() + @");
65 // </script>";
66 // }
67 jscript = @"<script type='text/javascript'>
68 addWkColumn('" + Calendar1.ClientID + "', " + getISOWeek(curMonth).ToString() + @");
69 </script>";
70
71 // Add script to page for execution of addWkColumn javascript function
72 Page.ClientScript.RegisterStartupScript(this.GetType(), "AddWeeknumbers", jscript);
73 }
74
75 /// <summary>
76 /// 获取几周
77 /// </summary>
78 /// <param name="day"></param>
79 /// <returns></returns>
80 private int getISOWeek(DateTime day)
81 {
82 return System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(day, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
83 }
84
85
86 protected void Calendar1_PreRender(object sender, EventArgs e)
87 {
88 if (Calendar1.VisibleDate.Year == 1 && Calendar1.VisibleDate.Month == 1)
89 {
90 // Add weeknumbers
91 DateTime curMonth = Calendar1.TodaysDate;
92 Calendar1.VisibleDate = new DateTime(curMonth.Year, curMonth.Month, 1);
93 addWeekNumberColumn(Calendar1.VisibleDate);
94 }
95 if (Calendar1.VisibleDate.Month == 1)
96 {
97 //DateTime curMonth;
98 Calendar1.VisibleDate = new DateTime(Calendar1.VisibleDate.Year, 1, 1);
99 addWeekNumberColumn(Calendar1.VisibleDate);
100 }
101 Calendar1.VisibleDate = new DateTime(Calendar1.VisibleDate.Year, Calendar1.VisibleDate.Month, 1);
102
103 addWeekNumberColumn(Calendar1.VisibleDate);
104
105 int i = getISOWeek(Calendar1.VisibleDate);
106 Response.Write(i.ToString() + "weeks");
107 }
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)