验证asp.net中的日期 [英] validate the dates in asp.net

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

问题描述

Start Date  DrstartDate(Date) DrstartMonth(month) DrstartYear(year)

  Issue Date  DrissDate(Date) DrissMonth(month) DrissYear(year)





页面加载代码如下





In page load code as follows

this.DrStartMonth.Items.Add("January");
          this.DrStartMonth.Items.Add("Feburary");
          this.DrStartMonth.Items.Add("March");
          this.DrStartMonth.Items.Add("April");
          this.DrStartMonth.Items.Add("May");
          this.DrStartMonth.Items.Add("June");
          this.DrStartMonth.Items.Add("July");
          this.DrStartMonth.Items.Add("August");
          this.DrStartMonth.Items.Add("September");
          this.DrStartMonth.Items.Add("October");
          this.DrStartMonth.Items.Add("November");
          this.DrStartMonth.Items.Add("December");

          for (int i = 1900; i <= 2100; i++)
          {
              this.DrStartYear.Items.Add(i.ToString());
          }

          for (int i = 1; i <= 31; i++)
          {
              this.DrStartDate.Items.Add(i.ToString());
          }


          this.DrIssueMonth.Items.Add("January");
          this.DrIssueMonth.Items.Add("February");
          this.DrIssueMonth.Items.Add("March");
          this.DrIssueMonth.Items.Add("April");
          this.DrIssueMonth.Items.Add("May");
          this.DrIssueMonth.Items.Add("June");
          this.DrIssueMonth.Items.Add("july");
          this.DrIssueMonth.Items.Add("August");
          this.DrIssueMonth.Items.Add("September");
          this.DrIssueMonth.Items.Add("October");
          this.DrIssueMonth.Items.Add("November");
          this.DrIssueMonth.Items.Add("December");

          for (int i = 1900; i <= 2010; i++)
          {
              this.DrIssueYear.Items.Add(i.ToString());
          }

          for(int i = 1; i<= 31; i++)
          {
              this.DrIssueDate.Items.Add(i.ToString());
          }



然后我有一个提交我要验证开始日期必须大于签发日期。



为什么我可以使用csharp在asp.net中验证。



请帮帮我。


Then i have one submit i want to validate Start date must be greater than issue date.

for that how can i validate in asp.net using csharp.

Please help me.

推荐答案

没关系开始日期必须大于签发日期 - 您根本不验证日期,因此非常容易输入非法日期:例如1992年2月31日。 />


我强烈建议您使用一对日历控件 [ ^ ]而不是下拉列表,并使用SelectedDate值直接比较它们 - 作为DateTime值,它们将与简单的大于测试进行比较。
Never mind "Start date must be greater than issue date" - you don't validate your dates at all, so illegal dates are very easy to enter: "31 Feb 1992" for example.

I would strongly suggest that you use a pair of Calendar controls[^] instead of drop down lists, and use the SelectedDate values to compare them directly - as DateTime vlaues they will compare with a simple "greater than" test.


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

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