利用CultureInfo來自訂Calendar的DayNameFormat
最近在小舖看到一篇文章
就是要如何自訂Calendar的DayNameFormat
小弟到網路上找了資料...寫個範例分享給大家呀..
C#範例
DayNameFormat.aspx
01 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DayNameFormat.aspx.cs" Inherits="DayNameFormat"
02 Culture="zh-TW" %>
03
04 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
05 <html xmlns="http://www.w3.org/1999/xhtml">
06 <head id="Head1" runat="server">
07 <title>DayNameFormat</title>
08 </head>
09 <body>
10 <form id="form1" runat="server">
11 <div>
12 <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
13 </div>
14 </form>
15 </body>
16 </html>
17
02 Culture="zh-TW" %>
03
04 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
05 <html xmlns="http://www.w3.org/1999/xhtml">
06 <head id="Head1" runat="server">
07 <title>DayNameFormat</title>
08 </head>
09 <body>
10 <form id="form1" runat="server">
11 <div>
12 <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
13 </div>
14 </form>
15 </body>
16 </html>
17
DayNameFormat.aspx.cs
01
using System;
02
using System.Data;
03
using System.Configuration;
04
using System.Collections;
05
using System.Web;
06
using System.Web.Security;
07
using System.Web.UI;
08
using System.Web.UI.WebControls;
09
using System.Web.UI.WebControls.WebParts;
10
using System.Web.UI.HtmlControls;
11
using System.Globalization;
12
using System.Threading;
13
14
public partial class DayNameFormat : System.Web.UI.Page
15
{
16
protected void Page_Load(object sender, EventArgs e)
17
{
18
string[] dayNames = { "週休", "1", "2", "3", "4", "5", "週休" };
19
CultureInfo culture = new CultureInfo("zh-TW");
20
culture.DateTimeFormat.AbbreviatedDayNames = dayNames;
21
Thread.CurrentThread.CurrentCulture = culture;
22
}
23
}

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

執行結果:
參考網址:
http://www.cnblogs.com/wangsaokui/archive/2006/09/26/10229.html