比较表单上显示为小时和分钟下拉菜单的两个时间
我一直在开发一个 .NET/C# 表单,其中包含两个由下拉列表构建的时间字段。时间 A 由两个小时和分钟下拉菜单组成,时间 B 也由两个小时和分钟下拉菜单组成。我需要比较两者,以确保时间 A 始终大于 B。
我可以使用 CompareValidator 来检查小时,这可以工作,但不考虑分钟。因此,让我们假设以下情况:
A = 11:00 B = 12:15 很好,我的验证接受了这一点,因为它应该这样做 A = 11:15 B = 11:00 被接受,因为小时数相等,但否则不应通过,因为分钟数未经验证。
在使用下拉列表的情况下,如何确保 B 始终等于或大于 A?如果我可以改变这一点,但不允许这样做,我会这样做。
I have been working on a .NET/C# form that contains two time fields that are built out of dropdowns. Time A is made up of two dropdowns for Hours and Minutes and Time B is made up of two drop downs for hours and minutes too. I need to compare the two in order to ensure that Time A is always greater than B.
I could just use a CompareValidator to check the hours, that works BUT doesn't take into account the minutes. So lets assume the following scenarios:
A = 11:00 B = 12:15 is fine my validation accepts this as it should do
A = 11:15 B = 11:00 is accepted because the hours are equal but otherwise shouldn't pass as the minutes aren't validated
How would you ensure B is always equal to or greater than A where dropdowns are used? I would if I could change this but not permitted to do so.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信最好的方法是有一个封装比较的方法,并在内部创建两个 DateTime 值 a 和 b,然后比较它们。
该方法将使用 UI 的值初始化 a 和 b。
I believe the best way is to have a method which encapsulates the comparison and internally is creating two DateTime values, a and b, and comparing them.
Such method will initialize a and b with the values of the UI.
为什么不添加一个 CustomValidator 并编写一些 javascript 函数来比较日期?
Why not add a CustomValidator and write a little javascript function to compare the dates?