如何实现在WEB FORM中实现一个类似WINFORM中的DATETIMEPICK的控件

wnobleman 2004-04-09 11:43:17
如何实现在WEB FORM中实现一个类似WINFORM中的DATETIMEPICK的控件
...全文
96 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
veryhappy 2004-04-11
  • 打赏
  • 举报
回复
用梅花雨日期控件吧
wnobleman 2004-04-11
  • 打赏
  • 举报
回复
大哥,发一份吧,挺急的!
wnobleman 2004-04-11
  • 打赏
  • 举报
回复
非常感谢,收到了!
wnobleman 2004-04-11
  • 打赏
  • 举报
回复
在顶一下!
blackant2 2004-04-10
  • 打赏
  • 举报
回复
刚才没有发完
blackant2 2004-04-10
  • 打赏
  • 举报
回复
一次只能发言三次
你给我留邮箱吧
wnobleman 2004-04-10
  • 打赏
  • 举报
回复
编译通过之后什么也显示不出来!
wnobleman 2004-04-10
  • 打赏
  • 举报
回复
能不能给打包的源码文件,最好在加上例子!
blackant2 2004-04-10
  • 打赏
  • 举报
回复
#region Render Overrides
protected override void CreateChildControls()
{

_TextBox=new TextBox();
_TextBox.ID="Text";
_TextBox.Attributes["Onfocus"]="javascript:calendar();";
_TextBox.TextChanged+=new EventHandler(raiseDateChanged);
//_TextBox.Width=Unit.Pixel((int)this.Width.Value-20);
this.Controls.Add(_TextBox);


_Button=new WebControl();
_Button.ID="Button";

_Button.BorderStyle=BorderStyle.Solid;
_Button.BorderWidth=Unit.Pixel(1);
_Button.Font.Name="webdings";
_Button.Attributes["onclick"]="javascript:calendar(document.all."+_TextBox.ClientID+")";
this.Controls.Add(_Button);

LiteralControl lc=new LiteralControl("6");
_Button.Controls.Add(lc);
}

protected override void OnPreRender(System.EventArgs e)
{
base.OnPreRender(e);
//如果没有注册脚本,则应注册脚本
if(!Page.IsClientScriptBlockRegistered("CalendarScript"))
{
String strScript="<script language='javascript'>\r\n<!--\r\n"
+"document.write(\"<div id=meizzCalendarLayer style='position: absolute; z-index: 9999; width: 144; height: 193; display: none'>\");"
+"document.write(\"<iframe name=meizzCalendarIframe scrolling=no frameborder=0 width=100% height=100%></iframe></div>\");"
+"function writeIframe()"
+"{var strIframe = \"<html><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312'><style>\"+"
+"\"*{font-size: 12px; font-family: 宋体}\"+"
+"\".bg{ color: \"+ WebCalendar.lightColor +\"; cursor: default; background-color: \"+ WebCalendar.darkColor +\";}\"+"
+"\"table#tableMain{ width: 142; height: 180;}\"+"
+"\"table#tableWeek td{ color: \"+ WebCalendar.lightColor +\";}\"+"
+"\"table#tableDay td{ font-weight: bold;}\"+"
+"\"td#meizzYearHead, td#meizzYearMonth{color: \"+ parent.WebCalendar.wordColor +\"}\"+"
+"\".out { text-align: center; border-top: 1px solid \"+ WebCalendar.DarkBorder +\"; border-left: 1px solid \"+ WebCalendar.DarkBorder +\";\"+"
+"\"border-right: 1px solid \"+ WebCalendar.lightColor +\"; border-bottom: 1px solid \"+ WebCalendar.lightColor +\";}\"+"
+"\".over{ text-align: center; border-top: 1px solid #FFFFFF; border-left: 1px solid #FFFFFF;\"+"
+"\"border-bottom: 1px solid \"+ WebCalendar.DarkBorder +\"; border-right: 1px solid \"+ WebCalendar.DarkBorder +\"}\"+"
+"\"input{ border: 1px solid \"+ WebCalendar.darkColor +\"; padding-top: 1px; height: 18; cursor: hand;\"+"
+"\" color:\"+ WebCalendar.wordColor +\"; background-color: \"+ WebCalendar.btnBgColor +\"}\"+"
+"\"</style></head><body onselectstart='return false' style='margin: 0px' oncontextmenu='return false'><form name=meizz>\";"
+"if (WebCalendar.drag){ strIframe += \"<scr\"+\"ipt language=javascript>\"+"
+"\"var drag=false, cx=0, cy=0, o = parent.WebCalendar.calendar; function document.onmousemove(){\"+"
+"\"if(parent.WebCalendar.drag && drag){if(o.style.left=='')o.style.left=0; if(o.style.top=='')o.style.top=0;\"+"
+"\"o.style.left = parseInt(o.style.left) + window.event.clientX-cx;\"+"
+"\"o.style.top = parseInt(o.style.top) + window.event.clientY-cy;}}\"+"
+"\"function document.onkeydown(){ switch(window.event.keyCode){ case 27 : parent.hiddenCalendar(); break;\"+"
+"\"case 37 : parent.prevM(); break; case 38 : parent.prevY(); break; case 39 : parent.nextM(); break; case 40 : parent.nextY(); break;\"+"
+"\"case 84 : document.forms[0].today.click(); break;} window.event.keyCode = 0; window.event.returnValue= false;}\"+"
+"\"function dragStart(){cx=window.event.clientX; cy=window.event.clientY; drag=true;}</scr\"+\"ipt>\"}"
+"strIframe += \"<select name=tmpYearSelect onblur='parent.hiddenSelect(this)' style='z-index:1;position:absolute;top:3;left:18;display:none'\"+"
+"\" onchange='parent.WebCalendar.thisYear =this.value; parent.hiddenSelect(this); parent.writeCalendar();'></select>\"+"
+"\"<select name=tmpMonthSelect onblur='parent.hiddenSelect(this)' style='z-index:1; position:absolute;top:3;left:74;display:none'\"+"
+"\" onchange='parent.WebCalendar.thisMonth=this.value; parent.hiddenSelect(this); parent.writeCalendar();'></select>\"+"
+"\"<table id=tableMain class=bg border=0 cellspacing=2 cellpadding=0>\"+"
+"\"<tr><td width=140 height=19 bgcolor='\"+ WebCalendar.lightColor +\"'>\"+"
+"\" <table width=140 id=tableHead border=0 cellspacing=1 cellpadding=0><tr align=center>\"+"
+"\" <td width=15 height=19 class=bg title='向前翻 1 月 快捷键:←' style='cursor: hand' onclick='parent.prevM()'><b><</b></td>\"+"
+"\" <td width=60 id=meizzYearHead title='点击此处选择年份' onclick='parent.funYearSelect(parseInt(this.innerText, 10))'\"+"
+"\" onmouseover='this.bgColor=parent.WebCalendar.darkColor; this.style.color=parent.WebCalendar.lightColor'\"+"
+"\" onmouseout='this.bgColor=parent.WebCalendar.lightColor; this.style.color=parent.WebCalendar.wordColor'></td>\"+"
+"\" <td width=50 id=meizzYearMonth title='点击此处选择月份' onclick='parent.funMonthSelect(parseInt(this.innerText, 10))'\"+"
+"\" onmouseover='this.bgColor=parent.WebCalendar.darkColor; this.style.color=parent.WebCalendar.lightColor'\"+"
+"\" onmouseout='this.bgColor=parent.WebCalendar.lightColor; this.style.color=parent.WebCalendar.wordColor'></td>\"+"
+"\" <td width=15 class=bg title='向后翻 1 月 快捷键:→' onclick='parent.nextM()' style='cursor: hand'><b>></b></td></tr></table>\"+"
+"\"</td></tr><tr><td height=20><table id=tableWeek border=1 width=140 cellpadding=0 cellspacing=0 \";"
+"if(WebCalendar.drag){strIframe += \"onmousedown='dragStart()' onmouseup='drag=false' onmouseout='drag=false'\";}"
+"strIframe += \" borderColorLight='\"+ WebCalendar.darkColor +\"' borderColorDark='\"+ WebCalendar.lightColor +\"'>\"+"
+"\" <tr align=center><td height=20>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr></table>\"+"
+"\"</td></tr><tr><td valign=top width=140 bgcolor='\"+ WebCalendar.lightColor +\"'>\"+"
+"\" <table id=tableDay height=120 width=140 border=0 cellspacing=1 cellpadding=0>\";"
+"for(var x=0; x<5; x++){ strIframe += \"<tr>\";"
+"for(var y=0; y<7; y++) strIframe += \"<td class=out id='meizzDay\"+ (x*7+y) +\"'></td>\"; strIframe += \"</tr>\";}"
+"strIframe += \"<tr>\";"
blackant2 2004-04-10
  • 打赏
  • 举报
回复
#region New Properties
[
Description("控件的暗色"),
Category("Appearance"),
Bindable(true),
]
public virtual System.Drawing.Color DarkColor
{
get
{
return _DarkColor;
}
set
{
_DarkColor=value;
}
}
[
Description("控件的亮色"),
Category("Appearance"),
Bindable(true),
]
public virtual System.Drawing.Color LightColor
{
get
{
return _LightColor;
}
set
{
_LightColor=value;
}
}
[
Description("得到或设置其控钮背景色"),
Category("Appearance"),
Bindable(true),
]
public virtual System.Drawing.Color BtnBgColor
{
get
{
return _BtnBgColor;
}
set
{
_BtnBgColor=value;
}
}
[
Description("得到或设置其控件的文字颜色"),
Category("Appearance"),
Bindable(true),
]
public virtual System.Drawing.Color WordColor
{
get
{
return _WordColor;
}
set
{
_WordColor=value;
}
}

[
Description("得到或设置其控件的暗文字颜色"),
Category("Appearance"),
Bindable(true),
]
public virtual System.Drawing.Color WordDark
{
get
{
return _WordDark;
}
set
{
_WordDark=value;
}
}
[
Description("得到或设置其控件的日期数字背景色"),
Category("Appearance"),
Bindable(true),
]
public virtual System.Drawing.Color DayBgColor
{
get
{
return _DayBgColor;
}
set
{
_DayBgColor=value;
}
}

//今天在日历上的标示背景色 _TodayColor
[
Description("得到或设置的今天在日历上的标示背景色"),
Category("Appearance"),
Bindable(true),
]
public virtual System.Drawing.Color TodayColor
{
get
{
return _TodayColor;
}
set
{
_TodayColor=value;
}
}

//日期显示的立体表达色 _BorderDark
[
Description("得到或设置日期显示的立体表达色"),
Category("Appearance"),
Bindable(true),
]
public virtual System.Drawing.Color BorderDark
{
get
{
return _BorderDark;
}
set
{
_BorderDark=value;
}
}

[
Description("允许拖放"),
Category("Behavior"),
Bindable(true)
]
public virtual bool AllowDrag
{
get
{
return _AllowDrag;
}
set
{
_AllowDrag=value;
}
}
[
Description("是否自动回传"),
Category("Behavior"),
Bindable(true),
]
public virtual bool AutoPostBack
{
get{return _AutoPostBack;}
set{_AutoPostBack=value;}
}
[
Description("得到或设置其日期"),
Category("Data"),
Bindable(true),
]
public virtual DateTime CurrentDate
{
get
{
this.EnsureChildControls();
//if(ViewState["Date"]==null)
// ViewState["Date"]=System.DateTime.Today;
//return (DateTime)ViewState["Date"];
try
{
DateTime dt=System.Convert.ToDateTime(_TextBox.Text);
return dt;
}
catch
{
DateTime dt=DateTime.Today;
_TextBox.Text=dt.ToString("yyyy-MM-dd");
return dt;
}
}
set
{
this.EnsureChildControls();
//this.ViewState["Date"]=value;
_TextBox.Text=value.ToString("yyyy-MM-dd");
}
}
#endregion
blackant2 2004-04-10
  • 打赏
  • 举报
回复
using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace BAWebLib
{
/// <summary>
/// BAWC_Calendar 的摘要说明。
/// </summary>
[ParseChildren(false)]
[PersistChildren(false)]

[Description("专用于ASP.Net Web应用程序的日期控件")]
[ValidationProperty("CurrentDate")]
[DefaultProperty("CurrentDate")]
[ToolboxData("<{0}:BAWC_Calendar runat=server></{0}:BAWC_Calendar>")]
public class BAWC_Calendar : System.Web.UI.WebControls.WebControl,IPostBackDataHandler,INamingContainer
{

public BAWC_Calendar():base(){}

/// <summary>
/// 将此控件呈现给指定的输出参数。
/// </summary>
/// <param name="output"> 要写出到的 HTML 编写器 </param>
///


#region Events
public event EventHandler DateChanged;

protected virtual void OnDateChanged(EventArgs e)
{
if(DateChanged!=null)
DateChanged(this,e);
}

#endregion

#region Implementation of IPostBackDataHandler
public virtual bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
{

if(CurrentDate!=Convert.ToDateTime(postCollection[postDataKey]))
{
CurrentDate=Convert.ToDateTime(postCollection[postDataKey]);
return true;
}
else
{
return false;
}
}
public virtual void RaisePostDataChangedEvent()
{
OnDateChanged(EventArgs.Empty);
}

private void raiseDateChanged( Object sender, EventArgs e )
{
OnDateChanged( e );
}

#endregion
wnobleman 2004-04-10
  • 打赏
  • 举报
回复
wnobleman@163.net
wnobleman 2004-04-10
  • 打赏
  • 举报
回复
wnobleman@163.com
thinkingforever 2004-04-09
  • 打赏
  • 举报
回复
到网上搜一个
wnobleman 2004-04-09
  • 打赏
  • 举报
回复
zai up yi xia!
wnobleman 2004-04-09
  • 打赏
  • 举报
回复
在顶一下!
wnobleman 2004-04-09
  • 打赏
  • 举报
回复
自己顶一下!
wnobleman 2004-04-09
  • 打赏
  • 举报
回复
这个我也会啊,但是现在要节省空间啊,有现成的控件也可以!
sneak 2004-04-09
  • 打赏
  • 举报
回复
有一种较为简便的方法:
做个用户控件:在该用户控件中放入三个DropDownList控件,分别代表年月日,并输入范围,再加上一些判断,再加入一些属性,即可。
自定义控件比较麻烦也,不过也是可以的,现在没空,要不然帮你做一个。
wnobleman 2004-04-09
  • 打赏
  • 举报
回复
就这个结果啊,那大哥你帮忙找一个吧,找不到啊 !

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧