日历简用
<asp:Calendar ID="Calendar2" runat="server" BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px"
onprerender="Calendar2_PreRender"
onselectionchanged="Calendar2_SelectionChanged" ShowGridLines="True"
Visible="true" Width="220px" ondayrender="Calendar2_DayRender">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
</asp:Calendar>
//-------------------------------------------------
string[,] myday;
public void CreateDay()
{
myday = new string[13, 32];
myday[1, 1] = "元旦";
myday[2, 14] = "情人节";
myday[3, 8] = "妇女节";
myday[4, 1] = "愚人节";
myday[5, 1] = "劳动节";
myday[5, 19] = "DE";
myday[6, 1] = "儿童节";
myday[7, 1] = "建党节";
myday[8, 1] = "建军节";
myday[9, 10] = "教师节";
myday[10, 1] = "国庆节";
myday[12, 24] = "圣诞节";
}
[Dependency]
public IProject GetProjectManager { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
}
protected void Calendar2_DayRender(object sender, DayRenderEventArgs e)
{
//CreateDay();
for (int i = 0; i < dt().Rows.Count; i++)
{
DateTime Begintime =Convert.ToDateTime(Convert.ToDateTime(dt().Rows[i]["SubStartTime"]).ToShortDateString());
DateTime Endtime =Convert.ToDateTime(Convert.ToDateTime(dt().Rows[i]["SubEndTime"]).ToShortDateString());
if (e.Day.Date>=Begintime && e.Day.Date <=Endtime)
{
//排除星期六、日 日历标记
if (!e.Day.IsWeekend)
{
if (!e.Day.IsToday)
{
e.Cell.BackColor = System.Drawing.Color.Red;
}
}
else if (e.Day.IsWeekend) // 星期六\日
{
e.Cell.BackColor = System.Drawing.Color.Green;
}
else if(e.Day.IsToday) //当天
{
e.Cell.BackColor = System.Drawing.Color.GreenYellow;
}
else if (e.Day.IsSelectable) //选中状态
{
e.Cell.BackColor = System.Drawing.Color.Gold;
}
}
}
}
/// <summary>
/// 获取所有的开始时间和结束时间
/// </summary>
/// <returns></returns>
private DataTable dt()
{
DataSet dataset = new DataSet();
if (Request.QueryString["id"] != null)
{
dataset = GetProjectManager.GetDsByUsername(Request.QueryString["id"].ToString(), System.DateTime.Now);
}
return dataset.Tables[0];
}
浙公网安备 33010602011771号