比较验证DATE [英] compare validate DATE

查看:81
本文介绍了比较验证DATE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将2个文本框中的2个数据与DATE值进行比较,我使用CompareValidator进行了比较,但对我不起作用,该怎么办?这是我的CompareValidator代码:

I want to compare 2 data in 2 textbox with DATE value,I used CompareValidator to compare them but it does not works for me how can I do? this is my CompareValidator code:

<asp:CompareValidator id="CompareValidator1" runat="server" ErrorMessage="Invalid Date!" Type="Date" ControlToValidate="SeconedDate_txt"               ControlToCompare="FirstDate_txt" Operator="GreaterThan"></asp:CompareValidator>

推荐答案

假设您的2个文本框分别是txtVal1和txtVal2
假设datatime mydate是您的值

suppose your 2 text-boxes are txtVal1 and txtVal2
suppose datatime mydate is your value

if(mydate.Equals(convert.todatetime(txtVal1)) && mydate.Equals(convert.todatetime(txtVal2)))
{
  // your code
}
else
{
  // date not match

}


尝试
<asp:CompareValidator ID="CompareValidatorBookingDeadline" runat="server"

ControlToCompare="TextBoxSeminarDate"

ControlToValidate="TextBoxBookingDeadline" Display="Dynamic"

ErrorMessage="Please check the seminar date and select appropriate date for booking deadline"

Operator="LessThanEqual"

Type="Date"

ValueToCompare="<%= TextBoxSeminarDate.Text.ToShortString() %>">*</asp:CompareValidator>


上面的代码使您可以比较两个输入日期,以避免无效的日期.在此示例中,我创建了两个文本框,并分别命名为"TextBoxSeminarDate""TextBoxBookingDeadline".预订截止日期必须早于研讨会日期.因此,我将Operator用作"LesThanEqual".
参考链接:-日期比较验证器控件ASP. NET [ ^ ]


The above code enable you to Compare two input dates to avoid invalid dates. In this example I have created two textboxes and namded as "TextBoxSeminarDate" and "TextBoxBookingDeadline". Booking deadline date must be before date to the Seminar date. Therefore I used Operator as "LesThanEqual".
Reference Link:- Date Compare Validator Control ASP.NET[^]


这篇关于比较验证DATE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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