日期:2014-05-18  浏览次数:20903 次

请大家帮帮忙,帮我解释下这个循环是什么意思,实现什么样的功能,万分感谢
public void fillyear(DropDownList list)
  {
  int i = 0, j = 0;
  list.Items.Clear();
  if (list.SelectedIndex == 0)
  {
  if (DateTime.Today.Month == 1)
  {
  j = DateTime.Today.Year - 1;
  for (i = j - 2; i <= DateTime.Today.Year - 1; i++)
  {
  list.Items.Add(new ListItem("" + j + "", "" + j + ""));
  j = j - 1;
  }
  }
  else
  {
  j = DateTime.Today.Year;
  for (i = j - 2; i <= DateTime.Today.Year; i++)
  {
  list.Items.Add(new ListItem("" + j + "", "" + j + ""));
  j = j - 1;
  }
  }

  }
  else
  {
  if (DateTime.Today.Month - 4 > 0)
  {
  j = DateTime.Today.Year;
  for (i = j - 2; i <= DateTime.Today.Year; i++)
  {
  list.Items.Add(new ListItem("" + j + "", "" + j + ""));
  j = j - 1;
  }
  }
  else
  {
  j = DateTime.Today.Year - 1;
  for (i = j - 2; i <= DateTime.Today.Year - 1; i++)
  {
  list.Items.Add(new ListItem("" + j + "", "" + j + ""));
  j = j - 1;
  }
  }
  }
  }
 

------解决方案--------------------
填充下拉,你自己运行一下不就知道结果了
------解决方案--------------------
看这个:public void fillyear(DropDownList list),就大概知道点东西了。填充下拉框年份的,运行一点效果就知道了。方法名fillyear改为FillYear,养成命名的好习惯。