代码如下:
using System;
………………
public partial class Default: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack ) //如果第一次加载页面使日历,label不可见
{
Calendar1.Visible = false;
Label1.Visible = false;
for (int y=1949;y<2050 ;y++ ) //给日期1下拉框添加年
{
DropDownList1.Items.Add(y.ToString());
}
for (int m = 1; m < 13;m++ ) //给日期2下拉框添加月
{
DropDownList2.Items.Add(m.ToString());
}
DropDownList1.Text = (DateTime.Now.Year).ToString(); //给下拉框默认显示当前日期
DropDownList2.Text = (DateTime.Now.Month).ToString();