当用户没有选择日期的时候, 默认显示当前的时间给TimeEdit. 只有当用户选了日期后, 才会把时间带进去.

效果图:

实现

C# Helper Code

        public static Action<DateEditSettings> DevDateTimeEdit(bool ab_Search, string as_Name, DateTime? adt_Date, bool ab_IsEnable, int ai_Width, int ai_Height, string as_DisplayFormatString = "", string as_DropDownEvent = "", string as_CloseUpEvent = "")
{
Action<DateEditSettings> DateEditSettings = (DateEditSetting =>
{
DateEditSetting.Name = as_Name;
DateEditSetting.Style.Add("float", "Left");
DateEditSetting.Date = Convert.ToDateTime(adt_Date);
DateEditSetting.ControlStyle.Border.BorderColor = System.Drawing.Color.LightGray;
DateEditSetting.Width = Unit.Percentage(ai_Width);
if (ab_IsEnable)
{
if (ab_Search)
{
DateEditSetting.ControlStyle.BackColor = GetColor.WhiteColor;
}
else
{
DateEditSetting.ControlStyle.BackColor = GetColor.EditableColor;
}
}
DateEditSetting.Properties.AllowNull = true; DateEditSetting.Properties.ConvertEmptyStringToNull = true;
DateEditSetting.Properties.NullText = string.Empty;
DateEditSetting.Height = System.Web.UI.WebControls.Unit.Pixel(ai_Height);
DateEditSetting.ControlStyle.CssClass = "form-control dx-dropdown";
DateEditSetting.Properties.EditFormat = EditFormat.Custom;
DateEditSetting.Properties.EditFormatString = as_DisplayFormatString;
DateEditSetting.Properties.ClientInstanceName = as_Name;
DateEditSetting.Enabled = ab_IsEnable;
DateEditSetting.Properties.NullText = "";
DateEditSetting.Properties.UseMaskBehavior = true;
DateEditSetting.Properties.TimeSectionProperties.Visible = true;
DateEditSetting.Properties.TimeSectionProperties.TimeEditProperties.EditFormat = EditFormat.Custom;
DateEditSetting.Properties.TimeSectionProperties.ShowHourHand = true;
DateEditSetting.Properties.TimeSectionProperties.TimeEditProperties.EditFormatString = "HH:mm:ss";
DateEditSetting.Properties.CalendarProperties.FastNavProperties.EnablePopupAnimation = true;
         // 这两个event是关键
DateEditSetting.Properties.ClientSideEvents.DropDown = as_DropDownEvent;
DateEditSetting.Properties.ClientSideEvents.CloseUp = as_CloseUpEvent;
});
return DateEditSettings;
}

  

CardView partial View, 当然你也可以直接在页面里面进行调用helper, 或者把Helper的code写到页面

  settings.Columns.Add(column =>
{
column.FieldName = "RecDate";
column.SetEditItemTemplateContent(Template =>
{
Html.DevExpress().Label(Utils.DevLabel("lbl" + ls_PanelName + "RecDate", "Act. Rec. Date", 20, 34, ":")).Render();
Html.DevExpress().DateEdit(Utils.DevDateTimeEdit(false, "dps" + ls_PanelName + "RecDate", DataBinder.Eval(Template.DataItem, "RecDate") as DateTime?, true, 44, 34, Utils.GetFormatString.DateTimeEdit,as_DropDownEvent:"ActRec_DropDown",as_CloseUpEvent:"ActRec_CloseUp")).Render();
});
}); //EstRecDate settings.EditFormLayoutProperties.Items.Add(i =>
{
i.ColumnName = "RecDate";
i.Width = Unit.Percentage(50);
i.ShowCaption = DefaultBoolean.False;
i.ColSpan = 2;
//i.ClientVisible = false;
});

  

Index  Javascript function

    //Display Calendar event.
  function ActRec_DropDown(s,e)
{
    //if user have not selected date, then set current time to it.
if(s.GetValue()==null)
{
s.GetTimeEdit().SetValue(new Date())
}
}
//Hide Calendar panel event.
function ActRec_CloseUp(s,e)
{
//Valid if user have not selected date, then set null to DateEdit. because DateEdit default date is "100/01/01", so we will add the cause.
if(s.GetValue()==null||yyyy_MM_dd(s.GetValue(),'/')=="100/01/01")
{
s.GetTimeEdit().SetValue(null);
s.SetValue(null);
}
}
function yyyy_MM_dd(ad_Date, as_Delimiter) {
var ls_Year = ad_Date.getFullYear(),
ls_Month = ad_Date.getMonth() + 1, // months are zero indexed
ls_Day = ad_Date.getDate();
var ls_MonthFormatted = ls_Month < 10 ? "0" + ls_Month : ls_Month,
ls_DayFormatted = ls_Day < 10 ? "0" + ls_Day : ls_Day;
return ls_Year.toString() + as_Delimiter + ls_MonthFormatted.toString() + as_Delimiter + ls_DayFormatted.toString();
};

  



  

Devexpress MVC DateEdit 设置默认的Time的更多相关文章

  1. DevExpress的DateEdit设置显示日期和时间

    1. 设置Mask.EditMask和DisplayFormat,EditFormat属性.设置为一致:'yyyy-MM-dd HH:mm';  //依照想要的显示格式设置此字符串. [csharp] ...

  2. MVC下设置默认页为index.html

    将RouteConfig代码修改为如下 public class RouteConfig { public static void RegisterRoutes(RouteCollection rou ...

  3. .NET MVC项目设置包含Areas中的页面为默认启动页

    利用vs创建一个MVC项目后,一般的默认启动页是根目录下-->Controllers-->HomeController-->Index这个方法对应的页面. 我先说下创建Areas的流 ...

  4. C#编译器优化那点事 c# 如果一个对象的值为null,那么它调用扩展方法时为甚么不报错 webAPI 控制器(Controller)太多怎么办? .NET MVC项目设置包含Areas中的页面为默认启动页 (五)Net Core使用静态文件 学习ASP.NET Core Razor 编程系列八——并发处理

    C#编译器优化那点事   使用C#编写程序,给最终用户的程序,是需要使用release配置的,而release配置和debug配置,有一个关键区别,就是release的编译器优化默认是启用的.优化代码 ...

  5. [saiku] 简化/汉化/设置默认页

    上一篇分析了schema文件 [ http://www.cnblogs.com/avivaye/p/4877832.html] 在安装完毕Saiku后,由于是社区版本,所以界面上存在很多升级为商业版的 ...

  6. MVC4.0 如何设置默认静态首页index.shtml

    1.不启用二级域名情况下(www.xxx.com)下设置默认静态首页index.shtml 通过配置IIS的默认文档,设置默认首页地址 然后在MVC的路由中写入忽略默认路由代码 routes.Igno ...

  7. DevExpress的DateEdit控件正确显示日期的周名称

    DevExpress 的控件相当好看而且很好用,但 DateEdit 在是显示周名时,只能显示一个“星”字. 以下是解决方法,此解决方法不需修改其源码,所以免去了重新编译的必要,可直接使用其发布的标准 ...

  8. 玩转控件:重绘DEVEXPRESS中DateEdit控件 —— 让DateEdit支持只选择年月 (提供源码下载)

      前言 上一篇博文<玩转控件:重绘ComboBox —— 让ComboBox多列显示>中,根据大家的回馈,ComboBox已经支持筛选了,更新见博文最后最后最后面.   奇葩 这两天遇到 ...

  9. DevExpress 利用DateEdit 仅显示和选择年份 z

    DevExpress只提供了选择月份的控件MonthEdit,并没提供选择选择年份的控件,目测是官方偷懒不想弄,因为要实现的方法也很简单,利用ComboBoxEdit添加年份数据即可,直接封装一个控件 ...

随机推荐

  1. 【VS开发】【图像处理】V4L2 pixel format

    目录(?)[-] v4l2_pix_format定义 2 具体Pixel Format定义 1. v4l2_pix_format定义 [cpp] view plain copy /* *  V I D ...

  2. js if(!!!e) {} 判断条件中的三个感叹号什么意思

    两个感叹号的意思就是,将变量转换为其对应的布尔值. !!e就是e对应的布尔值,true或者false. !!!e==!(!!e)==!true/!false=false/true;

  3. CDH管理节点扩容磁盘步骤

    把4个节点加12G内存,把hive的heap调到6G,按group重启服务让配置生效 注: 停服务前在yarn的application webui查flink的application id yarn ...

  4. AtCoder Beginner Contest 072

    这应该是我第二次打AtCoder, 题目其实并不难,就是自己经验不足想复杂了,再加上自己很笨,愣是做了97分钟才全做出来(最后三分钟,有点小激动..),看着前面大牛半个小时都搞完了,真心膜拜一下,代码 ...

  5. Android热修复、插件化、组件化

    模块化:项目按照独立的模块进行划分 组件化:将项目按照单一的组件来进行划分结构 项目组件化的重要环节在于,将项目按照模块来进行拆分,拆分成一个个业务module和其他支撑module(lib),各个业 ...

  6. 3D max导出的设置选项

    一3D max导出的设置选项

  7. Python的is和==区别

    字符串比较 1.比较字符串是否相同: ==:比较两个字符串内的value值是否相同 is:比较两个字符串的id值. 以上结果不同 比较数字时不能使用is,结果有时是True,有时是False,is 相 ...

  8. es6 filter() 数组过滤方法总结(转载)

    1.创建一个数组,判断数组中是否存在某个值 var newarr = [ { num: 1, val: 'ceshi', flag: 'aa' }, { num: 2, val: 'ceshi2', ...

  9. xcode中进行git代码管理

    http://www.cocoachina.com/ios/20140524/8536.html

  10. 【vue2.x基础】用npm起一个完整的项目

    1. 安装vue npm install vue -g 2.  安装vue-cli脚手架 npm install vue-cli -g 3. 安装webpack npm install webpack ...