Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
please help on below query.
What is the control to get only year calendar except date and month using mvc 5.

Thank You in advance.

What I have tried:

What is the control to get only year calendar except date and month using mvc 5.
Posted
Updated 18-Aug-16 18:13pm
Comments
Karthik_Mahalingam 18-Aug-16 6:02am    
you shall use a select box with the years data
Member 12224368 18-Aug-16 6:10am    
Thank you for your response Karthik.
could you please explain in detail, and please share any logic if possible.

Thank you

1 solution

try like this, if you want to display only the years,
if the range is less , you shall hardcode the values as
HTML
<select id="ddlYear">
           <option value="0">Select</option>
           <option value="1900">1900</option>
           <option value="1901">1900</option>
           <option value="1902">1900</option>
           .
           .
           .

           <option value="2015">1900</option>
           <option value="2016">1900</option>
       </select>


Configurable by using jquery.

HTML
<select id="ddlYear" ></select>


JavaScript
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
   <script>
       $(function () {
           var startYear = 1900;
           var endYear = 2020;
           var defaultValue = 'select'
           $('#ddlYear').append('<option value="' + defaultValue + '">' + defaultValue + '</option>');
           for (var i = startYear; i <= endYear; i++)
               $('#ddlYear').append('<option value="' + i + '">' + i + '</option>');


   });
       </script>
 
Share this answer
 
Comments
Member 12224368 19-Aug-16 3:40am    
thank you. its working
is there any control for only year calendar?
Karthik_Mahalingam 19-Aug-16 3:44am    
welcome
might be, check in this http://www.jqueryrain.com/
Member 12224368 19-Aug-16 3:49am    
Ok. Thank you Karthik
Karthik_Mahalingam 19-Aug-16 4:42am    
:)

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