http://hi.baidu.com/0598ccd/blog/item/5d540836f6ef96dfa3cc2bc4.html

解决方案 »

  1.   


    引用日历页面 用JAVASCRIPT调用
    <asp:TextBox ID="txtDate" runat="server" MaxLength="8" Width="80" ToolTip="Please see note 1"></asp:TextBox><a
                            href="javascript:;" onclick="window.open('PopupCalendar.aspx?textbox=txtDate','cal','width=300,height=230,left=350,top=250,statusbar=false')"><img
                                id="IMG4" runat="server" border="0" src="images/PopupCalendar.gif" /></a>
    弹出日历ASPX
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="PopupCalendar.aspx.cs" Inherits="PopCalendar" %><!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>Popup Calendar</title>
        <LINK href="CSS/Styles.css" type="text/css" rel="stylesheet">
        <script language="javascript">  </script>
    </head>
    <body topmargin="0" leftmargin="0">
        <form id="Form1" method="post" runat="server">
    <table height="220" cellSpacing="0" cellPadding="0" width="100%" border="0">
    <tr height="20">
    <td>
    <table height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
    <tr>
    <td vAlign="middle" align="center" width="10%" style="height: 21px"><asp:imagebutton id="BtnRefresh" runat="server" ToolTip="Refresh" ImageUrl="images/today.png"></asp:imagebutton></td>
    <td vAlign="middle" align="right" width="45%" style="height: 21px"><asp:dropdownlist id="CboYear" runat="server" Width="70px" CssClass="cssDTPComboBox" AutoPostBack="True"></asp:dropdownlist>&nbsp;<asp:label id="LblYear" runat="server" Width="45px" CssClass="cssDTPLabel">Year</asp:label></td>
    <td vAlign="middle" align="right" width="45%" style="height: 21px"><asp:dropdownlist id="CboMonth" runat="server" Width="75px" CssClass="cssDTPComboBox" AutoPostBack="True">
    <asp:ListItem Value="1">Jan</asp:ListItem>
    <asp:ListItem Value="2">Feb</asp:ListItem>
    <asp:ListItem Value="3">Mar</asp:ListItem>
    <asp:ListItem Value="4">Apr</asp:ListItem>
    <asp:ListItem Value="5">May</asp:ListItem>
    <asp:ListItem Value="6">Jun</asp:ListItem>
    <asp:ListItem Value="7">Jul</asp:ListItem>
    <asp:ListItem Value="8">Aug</asp:ListItem>
    <asp:ListItem Value="9">Sep</asp:ListItem>
    <asp:ListItem Value="10">Oct</asp:ListItem>
    <asp:ListItem Value="11">Nov</asp:ListItem>
    <asp:ListItem Value="12">Dec</asp:ListItem>
    </asp:dropdownlist>&nbsp;<asp:label id="LblMonth" runat="server" Width="45px" CssClass="cssDTPLabel">Month</asp:label></td>
    </tr>
    </table>
    </td>
    </tr>
    <tr height="10">
    <td><font size="1"></font></td>
    </tr>
    <tr height="170">
    <td vAlign="top" align="center"><asp:calendar id="CdrDatePicker" runat="server" ToolTip="Select Date" Width="240px" CssClass="cssDatePickerBase"
    ShowNextPrevMonth="False" FirstDayOfWeek="Sunday" NextMonthText=" " PrevMonthText=" " Height="170px" DayNameFormat="FirstTwoLetters">
    <TodayDayStyle CssClass="cssDatePickerToday"></TodayDayStyle>
    <SelectorStyle CssClass="cssDatePickerSelector"></SelectorStyle>
    <DayStyle CssClass="cssDatePickerDay"></DayStyle>
    <NextPrevStyle CssClass="cssDatePickerNextPrev"></NextPrevStyle>
    <DayHeaderStyle Font-Bold="True" CssClass="cssDatePickerDayHeader"></DayHeaderStyle>
    <SelectedDayStyle CssClass="cssDatePickerSelectedDay"></SelectedDayStyle>
    <TitleStyle CssClass="cssDatePickerTitle"></TitleStyle>
    <WeekendDayStyle CssClass="cssDatePickerWeekend"></WeekendDayStyle>
    <OtherMonthDayStyle CssClass="cssDatePickerOtherMonthDay"></OtherMonthDayStyle>
    </asp:calendar></td>
    </tr>
    <tr height="10">
    <td><font size="1"></font></td>
    </tr>
    <tr height="1">
    <td>
    <TABLE id="TblTimeControl" height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0"
    runat="server">
    <TR>
    <TD vAlign="middle" align="center" width="35%" style="height: 19px"></TD>
    <TD vAlign="middle" align="center" width="35%" style="height: 19px"></TD>
    <td vAlign="middle" align="center" style="height: 19px">
    <asp:LinkButton ID="hlSelectDate" Runat="server" CssClass="Hover" Font-Underline="True"></asp:LinkButton>
    </td>
    </TR>
    <TR height="10">
    <TD colSpan="3"><font size="1"></font></TD>
    </TR>
    </TABLE>
    </td>
    </tr>
    </table>
        </form>
    </body>
    </html>
      

  2.   

    弹出日历ASPX.CS
    using System;
    using System.Data;
    using System.Configuration;
    using System.ComponentModel;
    using System.Collections;
    using System.Drawing;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.SessionState;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    public partial class PopCalendar : System.Web.UI.Page
    {    #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }    /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.CboYear.SelectedIndexChanged += new System.EventHandler(this.CboYear_SelectedIndexChanged);
            this.CboMonth.SelectedIndexChanged += new System.EventHandler(this.CboMonth_SelectedIndexChanged);
            this.CdrDatePicker.SelectionChanged += new System.EventHandler(this.CdrDatePicker_SelectionChanged);
            this.hlSelectDate.Click += new System.EventHandler(this.hlSelectDate_Click);
            //this.Load += new System.EventHandler(this.Page_Load);    }
        #endregion    #region Events
        private void Page_Load(object sender, System.EventArgs e)
        {
            
            for (int i = 0; i < 12; i++)
                this.CboMonth.Items[i].Text = new DateTime(1, i + 1, 1).ToString("MMM"); //MM Month Format        
            if (!Page.IsPostBack)
            {
                //Adding the value to Combobox. [1900- thisYear]
                for (int iYear = 1990; iYear <= DateTime.Now.Year; iYear++)
                {
                    CboYear.Items.Add(new ListItem(iYear.ToString()));
                    //System.Math.Min(System.Threading.Interlocked.Increment(ref iYear), iYear - 1);
                    
                } 
                
                refreshControls();
                //Array.Copy(arr, arr.GetLength(1)*4, arrB, 0, arr.GetLength(1));
            }
            
        }
        private void hlSelectDate_Click(object sender, System.EventArgs e)
        {
            string ReturnDate = CdrDatePicker.SelectedDate.ToString("yyyyMMdd");
            returnToPage(ReturnDate);
        }
        private void CdrDatePicker_SelectionChanged(object sender, System.EventArgs e)
        {
            string retDate = CdrDatePicker.SelectedDate.ToString("yyyyMMdd");
            returnToPage(retDate);
        }
        private void CboYear_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            setCalendarDate();
        }
        private void CboMonth_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            setCalendarDate();
        }
        #endregion    #region "Private Methods"
        private void returnToPage(string retDate)
        {
            //"<script>window.opener." + Request.QueryString("field") + ".value ='" + ReturnDate + "';" + " " + "window.close();</script>")
            if (Request.QueryString["textbox"].ToString() != null)
            {
                string strScript = "<script>window.opener.document.forms[0]." + Request.QueryString["textbox"].ToString() + ".value='" + retDate + "';self.close();</script>";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "", strScript);
                //Response.Write(strScript);
                //Response.Write("<script>alert(window.opener.document.WebForm1.txtDate.value);</script>");
            }
        }
        private void setCalendarDate()
        {
            int day;
            int year = Int32.Parse(CboYear.SelectedValue.ToString());
            int month = Int32.Parse(CboMonth.SelectedValue.ToString());
            day = CdrDatePicker.SelectedDate.Day;
            if (day > DateTime.DaysInMonth(year, month))
            {
                day = DateTime.DaysInMonth(year, month);
            }
            CdrDatePicker.VisibleDate = new DateTime(year, month, day);
        }
        private void refreshControls()
        {
            DateTime SelectedDate;
            if (!(Request.QueryString["ShowDate"] == null))
            {
                SelectedDate = System.Convert.ToDateTime(Request.QueryString["ShowDate"]);
                CboYear.SelectedIndex = SelectedDate.Year - 1990;
                CboMonth.SelectedIndex = SelectedDate.Month - 1;
                CdrDatePicker.VisibleDate = SelectedDate.Date;
            }
            else
            {
                CboYear.SelectedIndex = DateTime.Now.Year - 1990;
                CboMonth.SelectedIndex = DateTime.Now.Month - 1;
                CdrDatePicker.VisibleDate = DateTime.Now.Date;
            }
        }
        #endregion
    }
    直接粘贴复制,改点小细节就可以用了
      

  3.   

    http://www.my97.net/dp/demo/index.htm