向日历控件中添加自定义内容

  • Post author:
  • Post category:其他



None.gif

<


html


>



None.gif


<


head


>



ExpandedBlockStart.gif
ContractedBlock.gif


<


script


language


=”C#”


runat


=”server”


>


dot.gif




InBlock.gif
String [][] holidays;

ExpandedSubBlockStart.gif
ContractedSubBlock.gif


void


Page_Load(Object Sender, EventArgs e)


dot.gif



{


InBlock.gif
holidays


=




new


String[


13


][];

InBlock.gif


for


(


int


n


=


0


; n


<


13


;n


++


)

InBlock.gif
holidays[n]


=




new


String[


32


];

InBlock.gif
holidays[


1


][


1


]


=







元旦





;

InBlock.gif
holidays[


1


][


26


]


=







澳大利亚国庆节





;

InBlock.gif
holidays[


2


][


2


]


=







土拨鼠日





;

InBlock.gif
holidays[


2


][


14


]


=







情人节





;

InBlock.gif
holidays[


3


][


17


]


=







圣帕特里克节





;

InBlock.gif
holidays[


4


][


1


]


=







愚人节





;

InBlock.gif
holidays[


5


][


1


]


=







国际劳动节





;

InBlock.gif
holidays[


6


][


15


]


=







我的生日





;

InBlock.gif
holidays[


7


][


15


]


=







我的纪念日





;

InBlock.gif
holidays[


8


][


15


]


=







我母亲的生日





;

InBlock.gif
holidays[


9


][


24


]


=







秋分





;

InBlock.gif
holidays[


12


][


26


]


=







节礼日





;

ExpandedSubBlockEnd.gif
}




ExpandedSubBlockStart.gif
ContractedSubBlock.gif


void


Calendar1_DayRender(object sender, DayRenderEventArgs e)


dot.gif



{


InBlock.gif
CalendarDay d


=


((DayRenderEventArgs)e).Day;

InBlock.gif
TableCell c


=


((DayRenderEventArgs)e).Cell;

ExpandedSubBlockStart.gif
ContractedSubBlock.gif


if


(d.IsOtherMonth)


dot.gif



{


InBlock.gif
c.Controls.Clear();

ExpandedSubBlockEnd.gif
}




ExpandedSubBlockStart.gif
ContractedSubBlock.gif


else




dot.gif



{


ExpandedSubBlockStart.gif
ContractedSubBlock.gif


try




dot.gif



{


InBlock.gif
string Hol


=


holidays[d.Date.Month][d.Date.Day];

InBlock.gif


if


(Hol


!=


string.Empty)

InBlock.gif
c.Controls.Add(


new


LiteralControl(





<br>







+


Hol));

ExpandedSubBlockEnd.gif
}




ExpandedSubBlockStart.gif
ContractedSubBlock.gif


catch


(Exception exc)


dot.gif



{


InBlock.gif
Response.Write (exc.ToString());

ExpandedSubBlockEnd.gif
}




ExpandedSubBlockEnd.gif
}




ExpandedSubBlockEnd.gif
}




ExpandedSubBlockStart.gif
ContractedSubBlock.gif


void


Date_Selected(object s, EventArgs e)


dot.gif



{


InBlock.gif
Label1.Text


=







选定日期为:







+


Calendar1.SelectedDate.ToShortDateString();

ExpandedBlockEnd.gif
}




None.gif



</


script


>



None.gif


</


head


>



None.gif


<


body


>



None.gif


<


h3


><


font


face


=”宋体”


>


向日历添加自定义内容


</


font


></


h3


>



None.gif


<


p


><


p


>



None.gif


<


form


runat


=server


>



None.gif


<


asp:Calendar


id


=Calendar1


runat


=”server”



None.gif
ondayrender


=”Calendar1_DayRender”



None.gif
onselectionchanged


=”Date_Selected”



None.gif
ShowGridLines


=”true”



None.gif
Font-Name


=”Verdana;Arial”



None.gif
Font-Size


=”9px”



None.gif
Width


=”500px”



None.gif
VisibleDate


=”01/01/2000″



None.gif
TitleStyle-BackColor


=”Gainsboro”



None.gif
TitleStyle-Font-Size


=”12px”



None.gif
TitleStyle-Font-Bold


=”true”



None.gif
DayStyle-VerticalAlign


=”Top”



None.gif
DayStyle-Height


=”50px”



None.gif
DayStyle-Width


=”14%”



None.gif
SelectedDate


=”1/1/0001″



None.gif
SelectedDayStyle-BackColor


=”Navy”



None.gif


/>



None.gif


<


p


>



None.gif


<


asp:Label


id


=Label1


runat


=”server”




/>



None.gif


</


form


>



None.gif


</


body


>



None.gif


</


html


>



None.gif

None.gif

转载于:https://www.cnblogs.com/yknb/archive/2006/06/02/415935.html