Devexpress MVC DateEdit 设置默认的Time
当用户没有选择日期的时候, 默认显示当前的时间给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的更多相关文章
- DevExpress的DateEdit设置显示日期和时间
1. 设置Mask.EditMask和DisplayFormat,EditFormat属性.设置为一致:'yyyy-MM-dd HH:mm'; //依照想要的显示格式设置此字符串. [csharp] ...
- MVC下设置默认页为index.html
将RouteConfig代码修改为如下 public class RouteConfig { public static void RegisterRoutes(RouteCollection rou ...
- .NET MVC项目设置包含Areas中的页面为默认启动页
利用vs创建一个MVC项目后,一般的默认启动页是根目录下-->Controllers-->HomeController-->Index这个方法对应的页面. 我先说下创建Areas的流 ...
- C#编译器优化那点事 c# 如果一个对象的值为null,那么它调用扩展方法时为甚么不报错 webAPI 控制器(Controller)太多怎么办? .NET MVC项目设置包含Areas中的页面为默认启动页 (五)Net Core使用静态文件 学习ASP.NET Core Razor 编程系列八——并发处理
C#编译器优化那点事 使用C#编写程序,给最终用户的程序,是需要使用release配置的,而release配置和debug配置,有一个关键区别,就是release的编译器优化默认是启用的.优化代码 ...
- [saiku] 简化/汉化/设置默认页
上一篇分析了schema文件 [ http://www.cnblogs.com/avivaye/p/4877832.html] 在安装完毕Saiku后,由于是社区版本,所以界面上存在很多升级为商业版的 ...
- MVC4.0 如何设置默认静态首页index.shtml
1.不启用二级域名情况下(www.xxx.com)下设置默认静态首页index.shtml 通过配置IIS的默认文档,设置默认首页地址 然后在MVC的路由中写入忽略默认路由代码 routes.Igno ...
- DevExpress的DateEdit控件正确显示日期的周名称
DevExpress 的控件相当好看而且很好用,但 DateEdit 在是显示周名时,只能显示一个“星”字. 以下是解决方法,此解决方法不需修改其源码,所以免去了重新编译的必要,可直接使用其发布的标准 ...
- 玩转控件:重绘DEVEXPRESS中DateEdit控件 —— 让DateEdit支持只选择年月 (提供源码下载)
前言 上一篇博文<玩转控件:重绘ComboBox —— 让ComboBox多列显示>中,根据大家的回馈,ComboBox已经支持筛选了,更新见博文最后最后最后面. 奇葩 这两天遇到 ...
- DevExpress 利用DateEdit 仅显示和选择年份 z
DevExpress只提供了选择月份的控件MonthEdit,并没提供选择选择年份的控件,目测是官方偷懒不想弄,因为要实现的方法也很简单,利用ComboBoxEdit添加年份数据即可,直接封装一个控件 ...
随机推荐
- 【VS开发】【图像处理】RGB Bayer Color分析
RGB Bayer Color分析 Bayer色彩滤波阵列 拜耳色彩滤波阵列(Bayer Color Filter Array,CFA)是非常有名的彩色图片的数字采集格式.色彩滤波器的模式如上图所示, ...
- Excel使用技巧大全(超全)
目录 Excel 使用技巧集锦 --163 种技巧 一. 基本方法 1. 快速选中全部工作表 2. 快速启动 Excel 3. 快速删除选定区域数据 4. 给单元格重新命名 5. 在 Excel 中选 ...
- start-all.sh启动HDFS,datanode没有启动
第一次格式化dfs后,启动并使用hadoop,之后如果再次重新执行了格式化(hdfs namenode -format) start-all.sh启动时就会遇到datanode无法启动的问题,通常情况 ...
- HDU 6175 算术
题目大意 求 $\sum_{i = 1}^{n} \sum_{j = 1}^{m} \mu(\lcm(i, j))$ . $ 1 \le n, m \le 10^6 $ . 分析 不妨设 $ n \l ...
- [codeforces1234F]Yet Another Substring Reverse
题目链接 大致题意为将某个子串进行翻转后,使得不包含相同字符的字符子串长度最长.只能翻转一次或零次. 设一个子串的状态为包含字符的二进制.如子串为$abacd$,则状态为$00000000000000 ...
- Ubuntu下TP5隐藏入口文件
部分内容是复制其他网友的博文,由于过了一段时间,找不到原文地址,再次表示感谢.以下是自己整理的,目的只是以后方便查阅 1.ubuntu或linux下找不到apache服务器配置文件httpd.conf ...
- python 压缩文件(解决压缩路径问题)
#压缩文件 def Zip_files(): datapath = filepath # 证据路径 file_newname = datapath + '.zip' # 压缩文件的名字 log.deb ...
- 剑指offer-递归和循环-python
-斐波那契数列- 大家都知道斐波那契数列(1.1.2.3.5.8.13.21.34.……),现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0). n<=39 斐波那契数 ...
- 微信小程序实现滑动删除效果
在一些app中,随处可见左滑动的效果,在微信小程序中,官方并未提供相关组件,需要我们自己动手写一个类似的效果 下面仅列举出核心代码,具体的优化需要根据你自身的需求 <view class='li ...
- qtdebug和release加载不同的文件配置
win32:CONFIG(release, debug|release): { LIBS +=$$PWD/../../../thirdparty\qwt\lib\qwt.lib LIBS +=$$PW ...