Calendar 日历加上可选择年月的选项。

 

using  System;
using  System.Data;
using  System.Configuration;
using  System.Collections;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;

public   partial   class  CalendarShow : System.Web.UI.Page
{
    
protected   void  Page_Load( object  sender, EventArgs e)
    {
        
if  ( ! IsPostBack)
        {
            
int  k  =  Convert.ToInt32(DateTime.Now.Year);

            
for  ( int  i  =   1900 ; i  <=  k; i ++ )
            {
                DPlist_year.Items.Add(i.ToString());
            }

            
for  ( int  i  =   1 ; i  <=   12 ; i ++ )
            {
                DPlist_month.Items.Add(i.ToString());
            }

        }
        
else
        {
            
int  year, month, day;
            year 
=  Convert.ToInt32(DPlist_year.SelectedItem.ToString());
            month 
=  Convert.ToInt32(DPlist_month.SelectedItem.ToString());
            day 
=  DateTime.Now.Day;
            DateTime querydate 
=   new  DateTime(year, month, day);
            MyCalendar.VisibleDate 
=  querydate;
        }
    }
    
protected   void  MyCalendar_SelectionChanged(Object sender, System.EventArgs e)
    {
        Response.Write(
" <script language="JavaScript"> " );
        Response.Write(
" parent.document.getElementById("birthday").value=" "   +  MyCalendar.SelectedDate.ToShortDateString()  +   " "; " );
        Response.Write(
" </script> " );
        
    }
}
< %@ Page  Language ="C#"  AutoEventWireup ="true"  CodeFile ="CalendarShow.aspx.cs"  Inherits ="CalendarShow"  % >

<! 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  id ="Head1"  runat ="server" >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=utf-8"   />
< link  href ="style.css"  rel ="stylesheet"  type ="text/css"   />
    
< title > 出生日期选择 </ title >
    
< script  language ="javascript"  src ="Images/popup.js" ></ script >
    
< SCRIPT  ID =clientEventHandlersJS  LANGUAGE =javascript>
    
function cancelcss()
    {parent.g_pop.close();}
    </SCRIPT
>
</ head >
< body >
    
< form  id ="form1"  runat ="server" >< table  width ="100%"  border ="0" >
  
< tr >
    
< td > &nbsp; 选择年月 < asp:DropDownList  ID ="DPlist_year"  runat ="server"  AutoPostBack ="True" >
        
</ asp:DropDownList >
        
< asp:DropDownList  ID ="DPlist_month"  runat ="server"  AutoPostBack ="True" >
        
</ asp:DropDownList > </ td >
  
</ tr >
  
< tr >
    
< td >< asp:Calendar  ID ="MyCalendar"  runat ="server"  OnSelectionChanged ="MyCalendar_SelectionChanged"  Width ="302px"  NextMonthText ="下月"  NextPrevFormat ="ShortMonth"  PrevMonthText ="上月" >
      
< SelectedDayStyle  BackColor ="Yellow"  ForeColor ="Red" ></ SelectedDayStyle >
        
< WeekendDayStyle  BackColor ="Info"   />
        
< TodayDayStyle  BackColor ="DarkTurquoise"   />
        
< OtherMonthDayStyle  BackColor ="#E0E0E0"   />
        
< DayStyle  BackColor ="Honeydew"  BorderColor ="White"  BorderStyle ="None"   />
        
< NextPrevStyle  BackColor ="White"  BorderColor ="#FFC0C0"   />
        
< DayHeaderStyle  BackColor ="LavenderBlush"  BorderColor ="White"  BorderStyle ="Solid"   />
        
< TitleStyle  BackColor ="Honeydew"   />
    
</ asp:Calendar ></ td >
  
</ tr >
</ table >
    
</ form >
</ body >
</ html >

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值