在动态添加的文本框中选择最低日期 [英] Selecting the lowest date in dynamically added text boxes

查看:65
本文介绍了在动态添加的文本框中选择最低日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我正在使用asp.net开发贷款计算器,我正在使用gridview在按钮点击时动态添加新行。动态gridview有大约5列,其中一列是Date。

我想要的是从所有添加的文本框中选择添加日期和当前日期之间差异最大的日期,然后我必须对其执行不同的操作..但我是无法做到这一点。



例如:



假设我在动态gridview中添加了3行。第一行的日期为2016年3月1日,第二行的日期为2016年6月1日,第三行的日期为2016年9月1日。现在我只想选择日期,从添加日期到当前日期之间的差异最大。 。在这种情况下,它将选择2016年3月1日,因为它具有截至今天的最大差异,即8.

事情是因为文本框是动态添加的,因此它们使用相同的ID即txtdate ..所以任何人都可以帮助请喜欢usimg jquery或javaScript。



如果有什么是unclea请随时询问。

寻找转发你的帮助。



我的尝试:



我已经搜索过谷歌,但我无法找到类似于我的问题

Hello there,

I am developing a loan calculator using asp.net and i am using a gridview to dynamically add new rows on button click. The dynamic gridview has around 5 columns out of which one is for Date.
What i want is to select the date with highest difference between months of the added date and current date by month from all the added textboxes and then i have to perform different operations on it..but i am unable to do that.

FOR EXAMPLE:

lets say i have added 3 rows in dynamic gridview. The first row has the date 1 March 2016, the second has the date 1 June 2016 and 3rd one contains the date 1 September 2016. Now i want to select only date with the higest difference between months from the date added till the current date..and in this case it will select 1st March 2016 because it has the highest difference between months till today i-e 8.
The thing is since the textboxes are being added dynamically therefore they are using a same id i-e txtdate..so can anyone help please like usimg jquery or javaScript preferably.

If anything is unclea please feel free to ask.
Looking forward to your help.

What I have tried:

I have searched google but i was unable to find a problem similar to mine

推荐答案

简单:这几乎是一项微不足道的任务 - 但这有很多功课,所以我'我给你没有代码!

从最简单的位开始:g et当前日期作为DateTime值 - 这是微不足道的。

然后遍历行并使用DateTime.TryParse将其转换为DateTime值。

使用每个转换后的值,并减去您之前提取的当前日期。这将为您提供TimeSpan值,该值具有TotalMinutes属性。比较每行的TotalMinutes会给出最高的数字,因此与今天的差异最大。
Easy: it's almost a trivial task - but this smells a lot of homework, so I'll give you no code!
Start with the simplest bit: get the current date as a DateTime value - that's trivial.
Then loop through the rows and use DateTime.TryParse to convert it to a DateTime value.
Use each converted value, and subtract the current date you fetched earlier. This gives you a TimeSpan value, which has a TotalMinutes property. Comparing the TotalMinutes for each row gives you the highest number, so the biggest difference from today.


这篇关于在动态添加的文本框中选择最低日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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