到页面时dropdownlist自动选择当前的季度

underlemontree 2010-04-11 12:12:09

<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才对,这个怎么实现,各位大虾们帮帮俺。


...全文
90 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
small_snowflower 2010-04-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 dopsop110 的回复:]
可以后台

C# code

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

这个算法真不错。
liuzhengyizenith 2010-04-11
  • 打赏
  • 举报
回复
我帮你绑定了一个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;
}
}
dopsop110 2010-04-11
  • 打赏
  • 举报
回复
可以后台

string[] season = new string[] { "1", "2", "3", "4" }; //季节
int index = (DateTime.Now.Month - 1) / 3;
ddl.SelectedValue = season[index];
liuzhengyizenith 2010-04-11
  • 打赏
  • 举报
回复
你可以在后台.cs文件写代码,获取当前时间,然后截取时间中的月份,然后判断,如果在1~3就是一季度,4~5就是2季度....,最后把值绑定到DropDownList控件上就OK啦
liaohui_1018 2010-04-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 dopsop110 的回复:]

可以后台
C# code

string[] season = new string[] { "1", "2", "3", "4" }; //季节
int index = (DateTime.Now.Month - 1) / 3;
ddl.SelectedValue = season[index];
[/Quote]
up
chen_ya_ping 2010-04-11
  • 打赏
  • 举报
回复
获取当前时间的月份,然后搞定就可以了。
yufenghua 2010-04-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 dopsop110 的回复:]

可以后台
C# code

string[] season = new string[] { "1", "2", "3", "4" }; //季节
int index = (DateTime.Now.Month - 1) / 3;
ddl.SelectedValue = season[index];
[/Quote]顶
libinlink 2010-04-11
  • 打赏
  • 举报
回复
<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>
libinlink 2010-04-11
  • 打赏
  • 举报
回复
测试通过

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Drop_jidu.SelectedIndex = DateTime.Now.Month / 4 ;
}
}
wuyq11 2010-04-11
  • 打赏
  • 举报
回复
public int GetQuarter(DateTime dt)
{
return dt.Month/4+1;
}

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧