初学:asp.net日历控件的使用
2007-06-25 16:41
363 查看
实现:主要是点击日历控件按钮,弹出一个日历控件窗口, 选择完日历控件的时间,返回给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()" />
到 <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
问题是:弹出的窗口的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()" />
到 <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
相关文章推荐
- ASP.NET Calendar日历(日期)控件使用方法
- ASP.NET中日历控件和JS版日历控件的使用方法
- ASP.NET中日历控件和JS版日历控件的使用方法(第5节)
- 不使用梅花雨日历控件而使用ASP.NET日历控件实现同样效果
- ASP.NET日历控件二次开发和使用
- ASP.NET Calendar日历(日期)控件使用方法
- ASP.NET 自定义服务器控件的使用
- asp.net下使用Request.From获取非服务器控件的值的方法
- ASP.NET使用文件上传控件上传图片
- Asp.net 2.0 TreeView控件使用jQuery无刷新添加节点详细说明
- ASP.NET自定义控件 第三天 使用控件状态的星级控件
- 使用ASP.NET Atlas XSLTView控件用XSLT修饰并显示XML数据
- 2015-11-04 asp.net 弹出式日历控件 选择日期 Calendar控件
- 有关C#+ASP.NET中用户控件(webusercontrol)使用问题2则
- ASP.NET FileUpload控件使用
- ASP.NET中设置两级菜单联动用户控件的属性为外部使用
- 使用 ASP.NET Atlas PageNavigator控件实现客户端分页导航
- Asp.Net -- 日历控件,和控件数组
- ASP.NET 2.0中使用webpart系列控件
- Asp.Net Ajax---TextBoxWateramrk控件使用