Click here to Skip to main content
16,014,294 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Updated 27-Nov-16 21:08pm

1 solution

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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900