2013-07-16 48 views
0

我已經使用了以下.net代碼。其中顯示了我在數據庫中存儲的假期日期。 但我想在日期上懸停鼠標時顯示一些消息。想要在日期上顯示鼠標懸停的消息

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data; 
using System.Data.SqlClient; 

public partial class _Default : System.Web.UI.Page 
{ 
string connection = @"server=TOPHAN-PC; Database=Tophan;uid=sa;pwd=123"; 
SqlConnection con = null; 
protected DataSet dsHolidays; 

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!IsPostBack) 
    { 

     con = new SqlConnection(connection); 
     Calendar1.VisibleDate = DateTime.Today; 
     FillHolidayDataset(); 
    } 
} 

protected void FillHolidayDataset() 
{ 
    DateTime firstDate = new DateTime(Calendar1.VisibleDate.Year,  Calendar1.VisibleDate.Month, 1); 
    DateTime lastDate = GetFirstDayOfNextMonth(); 
    dsHolidays = GetCurrentMonthData(firstDate, lastDate); 
} 

protected DateTime GetFirstDayOfNextMonth() 
{ 
    int monthNumber, yearNumber; 
    if (Calendar1.VisibleDate.Month == 12) 
    { 
     monthNumber = 1; 
     yearNumber = Calendar1.VisibleDate.Year + 1; 
    } 
    else 
    { 
     monthNumber = Calendar1.VisibleDate.Month + 1; 
     yearNumber = Calendar1.VisibleDate.Year; 
    } 
    DateTime lastDate = new DateTime(yearNumber, monthNumber, 1); 
    return lastDate; 
} 

protected DataSet GetCurrentMonthData(DateTime firstDate, DateTime lastDate) 
{ 
    DataSet dsMonth = new DataSet(); 
    try 
    {    
     //ConnectionStringSettings cs; 
     //cs = ConfigurationManager.ConnectionStrings["ConnectionString1"]; 
     //String connString = cs.ConnectionString; 
     //SqlConnection dbConnection = new SqlConnection(connString); 

     String query = "SELECT CDate FROM calender WHERE CDate >= @firstDate AND CDate < @lastDate"; 
     con.Open(); 
     SqlCommand dbCommand = new SqlCommand(query, con); 
     dbCommand.Parameters.Add(new SqlParameter("@firstDate", 
      firstDate)); 
     dbCommand.Parameters.Add(new SqlParameter("@lastDate", lastDate)); 

     SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(dbCommand); 
     sqlDataAdapter.Fill(dsMonth);      
    } 
    catch 
    { } 
    return dsMonth; 
} 


protected void Calendar1_VisibleMonthChanged(object sender, 
    MonthChangedEventArgs e) 
{ 
    FillHolidayDataset(); 
} 
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) 
{ 
    try 
    { 
     DateTime nextDate; 
     if (dsHolidays != null) 
     { 
      foreach (DataRow dr in dsHolidays.Tables[0].Rows) 
      { 
       nextDate = (DateTime)dr["CDate"]; 
       if (nextDate == e.Day.Date) 
       { 
        e.Cell.BackColor = System.Drawing.Color.Pink; 

       } 
      } 
     } 
    } 
    catch 
    { } 
} 
} 

通過使用此代碼,我發現它用顏色突出顯示了日期,但我想在日期上移動鼠標時收到一些消息。

+0

你想顯示一些靜態的信息?如果是,那麼你可以輕鬆地用jQuery來做!甚至在動態消息中,如果動態內容位於頁面某處,則可以使用jQuery來完成。 – Aisha

+0

任何人都可以幫助我解決這個問題。 – Sabyasachi

+0

如果我能夠設置一些靜態消息,那麼以後我可以使它成爲Dynamic.So如果你有jQuery代碼,請你分享一下代碼。 @Aisha – Sabyasachi

回答

0

你可以通過這個做到這一點:

$(document).ready(function() 
{  
    $("#holiday").hover(function() { 
    //Show whatever message on hover in 
    }, 
    function() { 
    //Show whatever message on hover out 
    } 
); }); 
+0

我在頁面中使用了默認的asp.net日曆控件。因此,我必須使用此代碼以及我必須在頁面中鏈接哪個默認jQuery。 @Aisha – Sabyasachi