您的位置:首页 > 编程语言 > ASP

单击ASP.NET日历控件单元格选择日期

2010-12-29 12:56 609 查看
单击ASP.NET日历控件老是选择数字才能选择这个日期,当数字很小的时候选择很不方便,以下方式可以单击单元格来选择日期:

Default.aspx代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebAppCalendar._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Calendar ID="Calendar1" runat="server" Height="212px" 
            ondayrender="Calendar1_DayRender" Width="390px"></asp:Calendar>
    </div>
    </form>
</body>
</html>


Default.aspx.cs代码:

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

namespace WebAppCalendar
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
        {
            //为日历单元格添加onClick事件
            e.Cell.Attributes.Add("onClick", e.SelectUrl);

            //鼠标变为手型
            e.Cell.Attributes.Add("onmouseover", "if(true) this.style.cursor='hand';");
        }
    }
}


运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: