62,041
社区成员
发帖
与我相关
我的任务
分享
<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才对,这个怎么实现,各位大虾们帮帮俺。
string[] season = new string[] { "1", "2", "3", "4" }; //季节
int index = (DateTime.Now.Month - 1) / 3;
ddl.SelectedValue = season[index];
<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>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Drop_jidu.SelectedIndex = DateTime.Now.Month / 4 ;
}
}