<td style="width: 100px; height: 22px;">
                    季度:<asp:DropDownList ID="Drop_jidu" runat="server" AutoPostBack="True" OnSelectedIndexChanged="Drop_jidu_SelectedIndexChanged">
                    <asp:ListItem Value="1">1</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    </asp:DropDownList></td>
赋值如上了,每次到这个页面时都是选择1,我想要到这个页面上时自动选择当前的季度,比如现在是4月份,应该是第二季度,那么到这个页面时dropdownlist应该选择2才对,这个怎么实现,各位大虾们帮帮俺。

解决方案 »

  1.   

    你可以在后台.cs文件写代码,获取当前时间,然后截取时间中的月份,然后判断,如果在1~3就是一季度,4~5就是2季度....,最后把值绑定到DropDownList控件上就OK啦
      

  2.   

    可以后台         string[] season = new string[] { "1", "2", "3", "4" }; //季节
                int index = (DateTime.Now.Month - 1) / 3;
                ddl.SelectedValue = season[index];
      

  3.   

    我帮你绑定了一个DropDownList,代码如下,你自己看看吧。
    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             DateTime mydate=DateTime.Now;
             int month = mydate.Month;
             DropDownList1.Text = getMonth(month).ToString();
             
        }
        private int getMonth(int month)
        {
            if (month >= 1 && month <= 3)
                return 1;
            else if (month >= 4 && month <= 7)
                return 2;
            else if (month >= 8 && month <= 10)
                return 3;
            else
                return 4;
        }
    }
      

  4.   

    public   int   GetQuarter(DateTime   dt)   
      {    
        return dt.Month/4+1;   
     }
      

  5.   

    测试通过     protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Drop_jidu.SelectedIndex = DateTime.Now.Month / 4 ;
            }
        }
      

  6.   

    <body>
        <form id="form1" runat="server">
        <div>
            季度:
            <asp:DropDownList ID="Drop_jidu" runat="server" AutoPostBack="True" >
                <asp:ListItem Value="1">1</asp:ListItem>
                <asp:ListItem Value="2">2</asp:ListItem>
                <asp:ListItem Value="3">3</asp:ListItem>
                <asp:ListItem Value="4">4</asp:ListItem>
            </asp:DropDownList>
        </div>
        </form>
    </body>