初学:asp.net日历控件的使用

实现:主要是点击日历控件按钮,弹出一个日历控件窗口, 选择完日历控件的时间,返回给textbox且关闭窗口.

问题是:弹出的窗口的left设置为window.event.clientX时,top参数为widnow.event.clientY时,却没有效果,只好写死参数啦;还有就是日历控件只能翻月,不能翻年,用处不大.

调用的代码如下:

 

< asp:TextBox  ID ="txtBegin"  runat ="server"   />< input  value ="日历"  type ="button"  onclick ="javascript:calendar_window=window.open('calendar.aspx?formname=<%= txtBegin.ClientID %>','calendar_window','width=162,top=230,left=430,height=220');calendar_window.focus()"   />
&nbsp; &nbsp; < asp:TextBox  ID ="txtEnd"  runat ="server"   />< input  type ="button"   value ="日历"  onclick ="javascript:calendar_window=window.open('calendar.aspx?formname=<%= txtEnd.ClientID %>','calendar_window','width=162,top=230,left=600,height=220');calendar_window.focus()"   />

日历窗口代码如下:

 

<% @ Page Language="C#"  %>

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

< script  runat ="server" >
    
void Calendar1_SelectionChanged(Object sender, EventArgs e)
    
{
        StringBuilder strJS 
= new StringBuilder();
        strJS.Append(
"<script type='text/javascript'>window.opener.document.getElementById('");
        strJS.Append(HttpContext.Current.Request.QueryString[
"formname"]);
        strJS.Append(
"').value='" + this.Calendar1.SelectedDate.ToString("d"));
        strJS.Append(
"';self.close();</scri").Append("pt>"); //工具问题
        this.Literal1.Text = strJS.ToString();
    }

    
void Calendar1_DayRender(Object sender,DayRenderEventArgs e)
    
{
        
if (e.Day.Date.ToString("d"== System.DateTime.Now.ToString("d"))
        
{
            e.Cell.BackColor 
= System.Drawing.Color.LightGray;
        }

    }

</ script >

< html  xmlns ="http://www.w3.org/1999/xhtml"   >
< head  runat ="server" >
    
< title > 无标题页 </ title >
</ head >
< body >
    
< form  id ="form1"  runat ="server" >
     
< asp:Calendar  id ="Calendar1"  runat ="server"  OnSelectionChanged ="Calendar1_SelectionChanged"  OnDayRender ="Calendar1_DayRender"  showtitle ="true"   SelectionMode ="Day"  BackColor ="#ffffff"  FirstDayOfWeek ="Monday"  BorderColor ="#000000"  ForeColor ="#00000"  Height ="60"  Width ="120" >
            
< TitleStyle  backcolor ="#000080"  forecolor ="#ffffff"   />
            
< NextPrevStyle  backcolor ="#000080"  forecolor ="#ffffff"   />
            
< OtherMonthDayStyle  forecolor ="#c0c0c0"   />
        
</ asp:Calendar >
        
< asp:Literal  id ="Literal1"  runat ="server" ></ asp:Literal >
    
</ form >
</ body >
</ html >
日历有一个selecteddate,是日历控件内的选定属性,如果要设置显示的初使值,还要同时设置VisibleDate
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值