如何验证下拉列表 [英] how to validate the dropdown list

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

问题描述

我有下拉列表如下





批量开始日期Dropdownlist1(日期)Dropdownlist2(月份)Dropdownlist3(年份)



发行日期Dropdownlist4(日期)Dropdownlist5(月)Dropdownlist6(年)







String startdate;

DateTime Batchstartdate;



startdate = this.Dropdownlist1.Text.ToString() .Trim()+ - + this.Dropdownlist2.Text.ToString()。Trim()+ - + this.Dropdownlist3.Text.ToString()。Trim();

Batchstartdate = Convert.ToDateTime(startdate.ToString());



string issuedate;

DateTime Batchissuedate;



issuedate = this.Dropdownlist4.Text.ToString()。Trim()+ - + this.Dropdownlist5.Text.ToString()。Trim()+ - + this.Dropdownlist6。 Text.ToString()。Trim();

Batchissuedate = Convert.ToDateTime(issuedate.ToString ());





i想验证发行日期不小于开始日期。



为什么我可以使用csharp进行验证。





if(startdate.ToString()< issate.ToString())

{

Label23.Text =开始日期必须大于发行日期;

return;

}



当我运行时显示错误如下

运算符'<'不能应用于操作数输入'string'和'string'





我怎么能用cshrp做什么。



请帮帮我。



问候,

Narasiman P.

i have dropdownlist as follows


Batch start date Dropdownlist1(Date) Dropdownlist2(month) Dropdownlist3(year)

Issue date Dropdownlist4(Date) Dropdownlist5(month) Dropdownlist6(year)



String startdate;
DateTime Batchstartdate;

startdate = this.Dropdownlist1.Text.ToString().Trim() + "-" + this.Dropdownlist2.Text.ToString().Trim() + "-" + this.Dropdownlist3.Text.ToString().Trim();
Batchstartdate = Convert.ToDateTime(startdate.ToString());

string issuedate;
DateTime Batchissuedate;

issuedate = this.Dropdownlist4.Text.ToString().Trim() + "-" + this.Dropdownlist5.Text.ToString().Trim() + "-" + this.Dropdownlist6.Text.ToString().Trim();
Batchissuedate = Convert.ToDateTime(issuedate.ToString());


i want to validate issue date is not less than start date.

for that how can i validate using csharp.


if (startdate.ToString() < issuedate.ToString())
{
Label23.Text = "Start Date must be greater than the Issue date";
return;
}

when i run shows error as follows
Operator '<' cannot be applied to operands of type 'string' and 'string'


for that how can i do using cshrp.

Please help me.

Regards,
Narasiman P.

推荐答案

你可以使用< DateTime本身的运算符:



Hi, you can use the < operator on DateTime itself:

if (startdate < issuedate)
 {
 Label23.Text = "Start Date must be greater than the Issue date";
 return;
 }


查看 DateTime.Compare 方法。



然后你可以这样做:



Have a look at the DateTime.Compare method.

Then you could do something like:

if(DateTime.Compare(Batchissuedate, Batchstartdate)>0)
{
    Label23.Text = "Start Date must be greater than the Issue date";
}






在你的代码中,startdate和authorate是两个字符串所以我们比较这两个日期,所以比较你的



Batchstartdate和Batchissuedate。



if(Batchstartdate< batchissuedate)>

{

Hi,

In your code startdate and issuedate are two strings so we compare those two dates so compare your

Batchstartdate and Batchissuedate.

if(Batchstartdate <batchissuedate)>
{
Label23.Text = "Start Date must be greater than the Issue date";



}


}


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

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