Asp.netPageLoad代码问题
protectedvoidPage_Load(objectsender,EventArgse){ArrayListalYear=newArrayList();ArrayL...
protected void Page_Load(object sender, EventArgs e)
{
ArrayList alYear = new ArrayList();
ArrayList alMonth = new ArrayList();
for (int i = 1900; i <= 2014; i++)
alYear.Add(i);
for (int i = 1; i <= 12; i++)
alMonth.Add(i);
if (!this.IsPostBack)
{
ddlYear.DataSource = alYear;
ddlYear.DataBind();
ddlYear.SelectedValue = DateTime.Now.Year.ToString();
ddlMonth.DataSource = alMonth;
ddlMonth.DataBind();
ddlMonth.SelectedValue = DateTime.Now.Month.ToString();
int year = Int32.Parse(ddlYear.SelectedValue);
int month = Int32.Parse(ddlMonth.SelectedValue);
BindDay(year, month);
ddlDay.SelectedValue = DateTime.Now.Day.ToString();
}
gvBorrowList_DataBind();//GridView控件叫gvBorrowList
}
private void BindDay(int year, int month)
{
ArrayList alDay = new ArrayList();
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
for (int i = 1; i <= 31; i++)
alDay.Add(i);
break;
case 2:
if (CheckLeap(year))
{
for (int i = 1; i <= 29; i++)
alDay.Add(i);
}
else
{
for (int i = 1; i <= 28; i++)
alDay.Add(i);
}
break;
case 4:
case 6:
case 9:
case 11:
for (int i = 1; i <= 30; i++)
alDay.Add(i);
break;
}
ddlDay.DataSource = alDay;
ddlDay.DataBind();
}
protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
{
int year, month;
year = Int32.Parse(ddlYear.SelectedValue);
month = Int32.Parse(ddlMonth.SelectedValue);
BindDay(year, month);
}
protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
{
int year, month;
year = Int32.Parse(ddlYear.SelectedValue);
month = Int32.Parse(ddlMonth.SelectedValue);
BindDay(year, month);
}
写在PageLoad里的代码是什么意思。我这里面写的是绑定时间的代码,那就是指页面一加 载就绑定时间吗? 展开
{
ArrayList alYear = new ArrayList();
ArrayList alMonth = new ArrayList();
for (int i = 1900; i <= 2014; i++)
alYear.Add(i);
for (int i = 1; i <= 12; i++)
alMonth.Add(i);
if (!this.IsPostBack)
{
ddlYear.DataSource = alYear;
ddlYear.DataBind();
ddlYear.SelectedValue = DateTime.Now.Year.ToString();
ddlMonth.DataSource = alMonth;
ddlMonth.DataBind();
ddlMonth.SelectedValue = DateTime.Now.Month.ToString();
int year = Int32.Parse(ddlYear.SelectedValue);
int month = Int32.Parse(ddlMonth.SelectedValue);
BindDay(year, month);
ddlDay.SelectedValue = DateTime.Now.Day.ToString();
}
gvBorrowList_DataBind();//GridView控件叫gvBorrowList
}
private void BindDay(int year, int month)
{
ArrayList alDay = new ArrayList();
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
for (int i = 1; i <= 31; i++)
alDay.Add(i);
break;
case 2:
if (CheckLeap(year))
{
for (int i = 1; i <= 29; i++)
alDay.Add(i);
}
else
{
for (int i = 1; i <= 28; i++)
alDay.Add(i);
}
break;
case 4:
case 6:
case 9:
case 11:
for (int i = 1; i <= 30; i++)
alDay.Add(i);
break;
}
ddlDay.DataSource = alDay;
ddlDay.DataBind();
}
protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
{
int year, month;
year = Int32.Parse(ddlYear.SelectedValue);
month = Int32.Parse(ddlMonth.SelectedValue);
BindDay(year, month);
}
protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
{
int year, month;
year = Int32.Parse(ddlYear.SelectedValue);
month = Int32.Parse(ddlMonth.SelectedValue);
BindDay(year, month);
}
写在PageLoad里的代码是什么意思。我这里面写的是绑定时间的代码,那就是指页面一加 载就绑定时间吗? 展开
1个回答
展开全部
protected void Page_Load(object sender, EventArgs e)
{
ArrayList alYear = new ArrayList();
ArrayList alMonth = new ArrayList();
for (int i = 1900; i <= 2014; i++)
alYear.Add(i);
for (int i = 1; i <= 12; i++)
alMonth.Add(i);
//此上是每次加载都执行一次
if (!this.IsPostBack)
{
//此处内的方法 只有第一次加载时执行
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询