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
    { }
}
}

通过使用此代码,我发现它用颜色突出显示了日期,但是当我在日期上移动鼠标时我想要一些消息。

4

1 回答 1

0

你可以这样做:

$(document).ready(function()
{       
  $("#holiday").hover(function () {
    //Show whatever message on hover in 
  },
  function () {
    //Show whatever message on hover out
  }
); });
于 2013-07-16T07:53:33.177 回答