嗨,我想比较2个文本框和gridview中的日期,这样一个必须小于其他文本框。 [英] Hi, I want to compare 2 textboxs with date in gridview such a way that one must be less than other.

查看:64
本文介绍了嗨,我想比较2个文本框和gridview中的日期,这样一个必须小于其他文本框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想比较2个文本框和gridview中的日期,这样一个必须小于其他。

Hi,
I want to compare 2 textboxs with date in gridview such a way that one must be less than other.

推荐答案

当然,您可以获取 TextBox.Text 字符串属性,尝试使用其中一个解析每个 System.DateTime 此结构的方法: Parse TryParse ParseExact TryParseExact ;然后你可以只使用运算符'<'',''>'',''> ='',''=''或''< =''来比较时间点:< a href =http://msdn.microsoft.com/en-us/library/system.datetime.aspx> http://msdn.microsoft.com/en-us/library/system.datetime.aspx [ ^ ]。< br $> b $ b

但是为什么?



看起来你倾向于使用表示数据的字符串而不是数据本身,是一个很大的错误。为什么不从你拥有的任何数据源中获取时间,比较它,只有它们显示为文本框或其他任何东西的字符串属性?



或者,您可以使用一些 DateTimePicked 而不是几乎无关的文本框。请参阅:

http://www.codeproject.com/KB/webforms/DateTimePicker .aspx [ ^ ]。



-SA
Of course, you could get TextBox.Text string properties, try to parse each into System.DateTime using one of the methods of this structure: Parse, TryParse, ParseExact or TryParseExact; and then you could compare the points in time just using the operators ''<'', ''>'', ''>='', ''='' or ''<='': http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

But why?

It looks like you tend to use strings representing data instead of data itself, which is a big mistake. Why not having time from whatever data source you have, comparing it, and only them display it as string properties of text boxes or anything else?

Alternatively, you can use some DateTimePicked instead of pretty much irrelevant text boxes. Please see:
http://www.codeproject.com/KB/webforms/DateTimePicker.aspx[^].

—SA


嗨亲爱的,



你使用文本框。我认为dateTimePicker1比文本框比较拖曳日期更好。如果你使用dateTimePicker1然后解决方案是



if(dateTimePicker1.Text> dateTimePicker1.Text)

{

//继续

}
hi dear,

you use textbox. I think dateTimePicker1 is better then textbox compare tow date. if you use dateTimePicker1 then solution is

if (dateTimePicker1.Text > dateTimePicker1.Text)
{
// Continue
}


这篇关于嗨,我想比较2个文本框和gridview中的日期,这样一个必须小于其他文本框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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