62,040
社区成员
发帖
与我相关
我的任务
分享
int h = DateTime.Now.Hour;
dl.Items.Add(new ListItem(h.ToString(), h.ToString()));
public partial class ManagementSystem_Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Bind();
}
private void Bind()
{
int curHour = DateTime.Now.Hour;
//增加时间段1
if (curHour >= 0 && curHour <= 7)
{
for (int i = 0; i <= 7; i++)
{
DDL_Hours.Items.Add(i.ToString());
}
}
//增加时间段2
if (curHour >= 8 && curHour <= 17)
{
for (int i = 8; i <= 17; i++)
{
DDL_Hours.Items.Add(i.ToString());
}
}
//增加时间段3
if (curHour >= 18 && curHour <= 23)
{
for (int i = 18; i <= 23; i++)
{
DDL_Hours.Items.Add(i.ToString());
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="ManagementSystem_Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DDL_Hours" runat="server">
</asp:DropDownList></div>
</form>
</body>
</html>