如何在数据时间选择器上进行显示验证 [英] how to make show validation on datatime picker

查看:85
本文介绍了如何在数据时间选择器上进行显示验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有2个日期时间选择器,即:

从日期开始:datetime picker1
迄今为止:datetime picker2
和一个搜索按钮(在我的表单中).

现在我的问题是如何在每个日期时间选择器上显示错误通知.

例如,如果任何用户单击搜索按钮而未选择任何数据选择器,即从日期"或到日期",则消息应为请先选择日期!".

另一个:
从日期:2011年7月4日到日期:2009年7月4日,错误应该出现,提示您输入的日期格式错误"

请帮我一个忙!

hello

i have 2 datetime picker ie:

From Date : datetime picker1
To Date : datetime picker2
and one search button in my form.

now my question is how to show the error notification on each datetime picker.

Example if any user click on search button with out selecting any datapicker i.e From date or To date..then message should come like "please select date first!!

another :
From Date :7-4-2011 To date: 7-4-2009 then error should come saying "you have enter wrong format of date"

plz help me out!!

推荐答案

用于第二次查询您可以将最小日期设置为当前日期,以便不能插入错误的格式.

对于第一个,您可以使用valuechanged属性,例如,如果仅更改了值,则搜索才开始.
for your second querry You can set minimum date as current date so the wrong format can''t be inserted.

And for the first one you can use valuechanged property ex if value is changed only then the search starts.


private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
if (dateTimePicker1.Value > dateTimePicker2.Value)
   {
MessageBox.Show("you have enter wrong format of date"");


如果您要实现复杂的逻辑,可以
编写一个继承ComapreValidator的自定义验证器,并在验证方法中编写所需的所有验证逻辑.

If you have complex logic to implement you could
write a custom validator inheriting ComapreValidator and write all the validation logic you want in the validation method.

public class V1 : CompareValidator
{
    protected override bool EvaluateIsValid()
    {
        //validation logic
        //......
        this.ErrorMessage = "message";//kind of validation error
    }

    //needed only if you want to validate controls that, by default cannot
    //be  validated, a calendar control (for example)
    protected override bool ControlPropertiesValid()
    {
        return true;
    }

}



要保留简单的代码,请取消选中启用客户端验证"或默认情况下覆盖属性设置为false,以便关闭javascript验证.
如果启用客户端验证,则还必须实现javascript逻辑...

希望有帮助.



to mantain simple the code, uncheke "Enable client validation" or override the property setting false by default, so that javascript validation in turned off.
If you enable client validation you have also to implement javascript logic...

Hope this help.


这篇关于如何在数据时间选择器上进行显示验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆