欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2017年07月05日 11:06:19   作者:china_skag  
這篇文章主要介紹了asp.net基于Calendar實(shí)現(xiàn)blog日歷功能,涉及asp.net使用Calendar控件操作日期與時(shí)間相關(guān)運(yùn)算技巧,需要的朋友可以參考下

本文實(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ù)庫(kù)查詢了。

在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++;
  }

在這里我們注意的是getArrayDay()方法是從數(shù)據(jù)庫(kù)里查詢當(dāng)月是否有日志的方法,它返回的是一個(gè)數(shù)組,我寫的內(nèi)容如下:

public int[] getArrayDay(int intYear, int intMonth)
{
  int[] intArray = new int[31];
  //從數(shù)據(jù)庫(kù)里選取符合要求的記錄,將日期存入數(shù)組
  string strSql = "select data from test where year(data)=" + intYear +
  " and month(data)=" + intMonth;
  //調(diào)用DbHelperOleDb自定義類中的ExecuteReader方法,它返回的是一個(gè)OleDbDataReader型
  OleDbDataReader dr = dbAccess.DbHelperOleDb.ExecuteReader(strSql);
  int i = 0;
  while (dr.Read())
  {
    if (i == 0)
    {
      intArray[i] = Convert.ToDateTime(dr["data"].ToString()).Day;
      string a=Convert.ToString(intArray[i]);
      i++;
    }
    else if (Convert.ToDateTime(dr["data"].ToString()).Day != intArray[i - 1])
    {
      intArray[i] = Convert.ToDateTime(dr["data"].ToString()).Day;
      i++;
    }
  }
  return intArray;
}

ok ,這樣就行了,我們運(yùn)行一下就可以看到效果了..

PS:這里再為大家分享幾款本站的在線日期工具供大家參考:

在線萬年歷日歷:
http://tools.jb51.net/bianmin/wannianli

網(wǎng)頁(yè)萬年歷日歷:
http://tools.jb51.net/bianmin/webwannianli

在線萬年歷黃歷flash版:
http://tools.jb51.net/bianmin/flashwnl

更多關(guān)于asp.net相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《asp.net操作json技巧總結(jié)》、《asp.net字符串操作技巧匯總》、《asp.net操作XML技巧總結(jié)》、《asp.net文件操作技巧匯總》、《asp.net ajax技巧總結(jié)專題》及《asp.net緩存操作技巧總結(jié)》。

希望本文所述對(duì)大家asp.net程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • .NET C#使用微信公眾號(hào)登錄網(wǎng)站

    .NET C#使用微信公眾號(hào)登錄網(wǎng)站

    這篇文章主要介紹了.NET C#使用微信公眾號(hào)登錄網(wǎng)站,教大家利用微信公眾號(hào)進(jìn)行網(wǎng)站登錄,感興趣的小伙伴們可以參考一下
    2016-08-08
  • jQuery+Ajax用戶登錄功能的實(shí)現(xiàn)

    jQuery+Ajax用戶登錄功能的實(shí)現(xiàn)

    前幾天把jbox源碼修改成仿QQ空間模擬窗口后發(fā)現(xiàn)有很多人在關(guān)注。今天就貼一下我利用該模擬窗口實(shí)現(xiàn)的用戶登錄功能的代碼。
    2009-11-11
  • asp.ent下合并兩個(gè)結(jié)構(gòu)相同的DataTable

    asp.ent下合并兩個(gè)結(jié)構(gòu)相同的DataTable

    今天遇到了一個(gè)情況,就是從一張數(shù)據(jù)表中讀取幾個(gè)符合條件1的客戶的信息,然后再讀取幾個(gè)符合條件2的客戶的信息,最后顯示出來.因?yàn)榍昂髢纱螖?shù)據(jù)的客戶信息的結(jié)構(gòu)是完全相同的,所以干脆合并成一個(gè)DataTable再賦值給GridView好了.
    2010-02-02
  • datagrid綁定list沒有數(shù)據(jù) 表頭不顯示的解決方法

    datagrid綁定list沒有數(shù)據(jù) 表頭不顯示的解決方法

    datagrid綁定list沒有數(shù)據(jù) 表頭不顯示的問題,那是因?yàn)?綁定了null,你給list new一下就好 表頭就會(huì)有啦
    2013-05-05
  • ASP.NET2.0中用Gridview控件操作數(shù)據(jù)的代碼

    ASP.NET2.0中用Gridview控件操作數(shù)據(jù)的代碼

    在ASP.NET 2.0中,加入了許多新的功能和控件,相比asp.net 1.0/1.1,在各方面都有了很大的提高
    2012-10-10
  • 如何判斷?.NET?Core?應(yīng)用程序以管理員身份運(yùn)行的

    如何判斷?.NET?Core?應(yīng)用程序以管理員身份運(yùn)行的

    這篇文章主要介紹了如何判斷?.NET?Core?應(yīng)用程序是以管理員身份運(yùn)行的,我們需要知道當(dāng)前程序是否以管理員身份運(yùn)行,以便執(zhí)行一些需要特殊權(quán)限的操作,下面為我們就來學(xué)習(xí)具體的方法吧,需要的朋友可以參考一下
    2022-03-03
  • Asp.net?mvc實(shí)現(xiàn)上傳頭像加剪裁功能

    Asp.net?mvc實(shí)現(xiàn)上傳頭像加剪裁功能

    這篇文章主要介紹了實(shí)現(xiàn)Asp.net?mvc上傳頭像加剪裁功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2015-08-08
  • 詳解.net core日記記錄

    詳解.net core日記記錄

    這篇文章主要介紹了.net core的日記記錄,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • asp.net微軟圖表控件使用示例代碼分享

    asp.net微軟圖表控件使用示例代碼分享

    這篇文章主要介紹了asp.net微軟圖表控件使用示例代碼,有需要的朋友可以參考一下
    2013-12-12
  • C#.NET發(fā)送郵件的實(shí)例代碼

    C#.NET發(fā)送郵件的實(shí)例代碼

    這篇文章介紹了C#.NET發(fā)送郵件的實(shí)例代碼,有需要的朋友可以參考一下,希望對(duì)你有所幫助
    2013-07-07

最新評(píng)論