请问,可不可以从数据库中查处数据绑定在Calendar上,在相应的日期上如果有记录的话,要显示不同颜色的,请大家帮忙啊
------解决方案--------------------------------------------------------
下面找吧.有你需要的.正好我也做过.
private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
// if(!Page.IsPostBack)
// {
DateTime dt =new DateTime(1,1,1);
if(this.Calendar1.SelectedDate.CompareTo(dt)==0)
// if(aa== "0 ")
{
dbaAppoint.getHolidayDateSet(ref ds,dateStart,dateEnd,Application[ "OleConn "].ToString());
for(int i = 0;i <ds.Tables[ "table "].Rows.Count;i++)
{
for(int j =14;j <23;j++)
{
if(ds.Tables[ "table "].Rows[i][j].ToString()!= "0 ")
{
try
{
DateTime temp= Convert.ToDateTime(ds.Tables[ "table "].Rows[i][0].ToString()+ "- "+ds.Tables[ "table "].Rows[i][1].ToString().PadLeft(2, '0 ')+ "- "+ds.Tables[ "table "].Rows[i][j].ToString().PadLeft(2, '0 '));
if(e.Day.Date.CompareTo(temp.Date)==0)
{
e.Day.IsSelectable = false;
e.Cell.ForeColor = Color.Red;
// e.Cell.Enabled =false;
}
}
catch
{
}
}
}
}
ds.Clear();
if(e.Day.Date.DayOfWeek.CompareTo(DayOfWeek.Sunday)==0)
{
e.Cell.ForeColor = Color.Red;
}
if(e.Day.Date.AddDays(-1).CompareTo(DateTime.Now) <0)
{
e.Day.IsSelectable = false;
e.Cell.Enabled =false;
}
if(DateTime.Now.AddMonths(1).Date.CompareTo(e.Day.Date) <=0)
{
e.Day.IsSelectable = false;
e.Cell.Enabled =false;
}
if(e.Day.IsOtherMonth==true)
{
e.Day.IsSelectable = false;
}
if(e.Day.IsWeekend==true)
{
e.Day.IsSelectable =false;
}
}
}