比较两个用时间值填充的DropDownList的验证 [英] Compare Validation of Two DropDownList filled with Time Value
问题描述
我在C#中使用Asp.Net.
我有4个下拉列表,第1个和第3个Dropdownlist包含小时"作为从00-23(小时)开始的列表项,第2和第4个包含分钟"作为从00到59(分钟)开始的ListItems.现在,我该如何比较小时下拉列表值以发现时差.
是否有任何验证控件可以在客户端进行验证?
我们可以比较两个用时间值填充的DropDownList的验证吗?
如果有人知道答案,请回复给我.
谢谢
Hi,
I am using Asp.Net with C#.
I have 4 dropdownlists 1st and 3 Dropdownlist contains Hours as List Items starting from 00-23(hours), 2nd and 4th one contains Minutes as ListItems starting from 00 to 59(minutes). Now how do i compare hours dropdownlist values in order to find time difference.
Is there any Validation control to validate it at client side?
Can we do Compare Validation of Two DropDownList filled with Time Value?
if anybody know answer for this please reply it to me.
Thanks
推荐答案
客户端与javascript的日期差异:
Client side date difference with javascript:
<script type="text/javascript">
var date1 = new Date(2011, 1, 16); //Months are 0-11 in javascript
var date2 = new Date(2011, 1, 1);
//get 1 day in milliseconds
var one_day = 1000*60*60*24;
document.write(Math.ceil((date1.getTime() - date2.getTime()) / one_day);
</script>
使用自定义验证.定制验证控件的示例如下:
Use custom validation. Example of custom validation control bellow:
<asp:Label id=lblOutput runat="server"
Text="Enter an even number:"
Font-Name="Verdana"
Font-Size="10pt">
<asp:CustomValidator id="CustomValidator1"
ControlToValidate="Text1"
OnServerValidate="ServerValidation"
Display="Static"
ErrorMessage="Not an even number!"
ForeColor="green"
Font-Name="verdana"
Font-Size="10pt"
runat="server">
<asp:Button id="Button1"
Text="Validate"
OnClick="ValidateBtn_OnClick"
runat="server"/>
void ValidateBtn_OnClick(object sender, EventArgs e)
{
if (Page.IsValid)
{
lblOutput.Text = "Page is valid.";
}
else
{
lblOutput.Text = "Page is not valid!";
}
}
void ServerValidation (object source, ServerValidateEventArgs arguments)
{
int i = int.Parse(arguments.Value);
arguments.IsValid = ((i%2) == 0);
}
这篇关于比较两个用时间值填充的DropDownList的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!