一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

控件代码共享--日期选择控件

时间:2008-01-12 编辑:简简单单 来源:一聚教程网

 
思路:实现日期年月日的选择
1、可以设定年的起止年份
2、排除不正确日期选择的可能
3、使用javascript实现控制
4、使用Text属性方便获取设置日期值
=================================
代码如下:
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Web.UI;
using System.Web.UI.Design.WebControls;
using System.Web.UI.WebControls;
namespace JSY
{
///
/// AspNetDate 选择输入日期控件
///

[DefaultProperty("Text"),
ParseChildren(false),
PersistChildren(false),
Description("专用于ASP.Net Web应用程序的日期控件"),
Designer(typeof(DateDesigner)),
ToolboxData("<{0}:JSYNetDate runat=server>")]
public class JSYNetDate:Panel,INamingContainer,IPostBackDataHandler
{
#region 属性
///
/// 获取/设置日期值。
///

[Bindable(true),
Browsable(true),
Description("日期值"),
Category("外观"),
DefaultValue("")]
public string Text
{
get
{
if (ViewState["Text"] != null)
{
return ViewState["Text"].ToString();
}
else
{
if (IsNull)
{
return "";
}
else
{
DateTime date=System.DateTime.Today;
string str="";
switch (DateFormat)
{
case "YMD":
str=date.ToString("yyyy-MM-dd",System.Globalization.DateTimeFormatInfo.InvariantInfo);

热门栏目