国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net基于Calendar實(shí)現(xiàn)blog日歷功能示例

2024-07-10 12:49:03
字體:
供稿:網(wǎng)友

本文實(shí)例講述了asp.net基于Calendar實(shí)現(xiàn)blog日歷功能。,具體如下:

怎樣用.net的Calendar控件來實(shí)現(xiàn)blog中站點(diǎn)日歷的效果呢,我們知道站點(diǎn)日歷最重要的功能就是,顯現(xiàn)在哪天blog主人寫了日志,點(diǎn)擊日期,你將進(jìn)入所選日期的日志列表,

首先,我們知道.net中的服務(wù)器控件是會(huì)進(jìn)行Postback的,Calendar控件中的第一天在點(diǎn)擊時(shí),就會(huì)進(jìn)行一次postback我們要做的就是改變它默認(rèn)的鏈接,使它不觸發(fā)postback事件,其次,就是要知道哪一天有沒有日志。至于有沒有日志,就要去數(shù)據(jù)庫查詢了。

在Calendar中有一個(gè)DayRender事件,該事件在呈現(xiàn)每一天時(shí)觸發(fā),我們可以從這里入手,首先定義一個(gè)數(shù)組變量:

private int[] arrCurrentDays, arrPreDays, arrNextDays; //三個(gè)變量分別是當(dāng)前月,前一月,和下一個(gè)月private int intCurrentMonth, intPreMonth, intNextMonth; //三個(gè)整型數(shù)組存放相對(duì)月份寫有blog的日期

然后在Calendar的DayRender事件中寫下如下代碼:

CalendarDay d = ((DayRenderEventArgs)e).Day;TableCell c = ((DayRenderEventArgs)e).Cell;// 初始化當(dāng)前月有Blog的日期數(shù)組if (intPreMonth == 0){  intPreMonth = d.Date.Month; // 注意:日歷控件初始化時(shí)我們得到的第一個(gè)月并不是當(dāng)前月,而是前一個(gè)月的月份  intCurrentMonth = intPreMonth + 1;  if (intCurrentMonth > 12)    intCurrentMonth = 1;  intNextMonth = intCurrentMonth + 1;  if (intNextMonth > 12)    intNextMonth = 1;  arrPreDays = getArrayDay(d.Date.Year, intPreMonth); //得到前一個(gè)月有blog的日期數(shù)組  arrCurrentDays = getArrayDay(d.Date.Year, intCurrentMonth);//得到當(dāng)月有blog的日期數(shù)組  arrNextDays = getArrayDay(d.Date.Year, intNextMonth);//得到下個(gè)月有blog的日期數(shù)組}int j = 0;if (d.Date.Month.Equals(intPreMonth)){  while (!arrPreDays[j].Equals(0))  {    if (d.Date.Day.Equals(arrPreDays[j]))    {      c.Controls.Clear();      c.Controls.Add(new LiteralControl("<a href="day.aspx?year=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" mce_href="day.aspx?year=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" " + d.Date.Year + "&month=" +      d.Date.Month + "&day=" + d.Date.Day + ">" + d.Date.Day + "</a>"));    }    j++;  }}else if (d.Date.Month.Equals(intCurrentMonth)){  while (!arrCurrentDays[j].Equals(0))  {    if (d.Date.Day.Equals(arrCurrentDays[j]))    {      c.Controls.Clear();      c.Controls.Add(new LiteralControl("<a href="day.aspx?year=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" mce_href="day.aspx?year=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" " + d.Date.Year + "&month=" +      d.Date.Month + "&day=" + d.Date.Day + " title=查看"+d.Date.Day+"日日志>" + d.Date.Day + "</a>"));    }    j++;  }}else if (d.Date.Month.Equals(intNextMonth)){  while (!arrNextDays[j].Equals(0))  {    if (d.Date.Day.Equals(arrNextDays[j]))    {      c.Controls.Clear();      c.Controls.Add(new LiteralControl("<a href="day.aspx?year=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" mce_href="day.aspx?year=" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" " + d.Date.Year + "&month=" +      d.Date.Month + "&day=" + d.Date.Day + ">" + d.Date.Day + "</a>"));    }    j++;  }            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 进贤县| 临洮县| 南部县| 商洛市| 东光县| 攀枝花市| 邳州市| 图木舒克市| 江津市| 泽普县| 二连浩特市| 永丰县| 海阳市| 江油市| 乐亭县| 双辽市| 寿阳县| 容城县| 桑日县| 额敏县| 万载县| 贵定县| 张家界市| 抚宁县| 嵊泗县| 富裕县| 大英县| 石阡县| 安阳县| 茌平县| 庆云县| 安图县| 太谷县| 竹北市| 宁明县| 南部县| 平定县| 灌南县| 安远县| 景洪市| 额敏县|