Introduction:
In this article I will explain how to set months range or years range in JQuery calendar control in asp.net.
Download
sample code attached
In this article I will explain how to set months range or years range in JQuery calendar control in asp.net.
Description:
In previous post I explained show multiple months in calendar control and calendar control with dropdownlist selection for month and year. Now I will explain how to set months and years range in jquery calendar control.
In previous post I explained show multiple months in calendar control and calendar control with dropdownlist selection for month and year. Now I will explain how to set months and years range in jquery calendar control.
Suppose now if we want to allow user to
select only within 10 or 15 days or 1 month range then we can set those values
very easily and previously I explained calendar control with dropdownlist
selection for month and year for that we can set how many years
range we display it in year dropdown.
To implement this one first open Visual Studio and create new website after that write following code in your aspx page
To implement this one first open Visual Studio and create new website after that write following code in your aspx page
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.19.custom.css"
rel="stylesheet"
/>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.19.custom.min.js"></script>
<script type = "text/javascript">
$(function()
{
$("#txtMonthRange").datepicker({
minDate: 0,
maxDate: '+1M',
showButtonPanel: true
});
$("#txtYearRange").datepicker({
changeMonth: true,
changeYear:true,
yearRange:'1970:2010'
})
});
</script>
<style type="text/css">
.ui-datepicker { font-size:8pt !important}
</style>
</head>
<body>
<form id="form1"
runat="server">
<div class="demo">
<b>Month Range:</b> <asp:TextBox ID="txtMonthRange"
runat="server"/>
<b>Year Range:</b><asp:TextBox ID="txtYearRange" runat="server"/>
</div>
</form>
</body>
</html>
|
If
you observe above code in header section I added some of script files and css
classes by using those files we will display calendar control with beautiful
css style. You can get those files by downloading attached sample.
If
you observe script in header section
$("#txtMonthRange").datepicker({
minDate: 0,
maxDate: '+1M',
showButtonPanel: true
});
|
In
above script
minDate: I set it as 0 means it won’t allow us to select
before today date
maxDate: Here I set as '+1M' means it will allow us to select upto
one month dates.
If we want to set to 10 days range then we will change '+1M' to '+10'
other function will be
$("#txtYearRange").datepicker({
changeMonth: true,
changeYear:true,
yearRange:'1970:2010'
})
|
In above function I set yearRange: '1970:2010'
in year dropdown that will display years from 1970 to 2010
After
completion of aspx page design and your code modifications just run your
application and check your calendar control that would be like below demo
Demo
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
3 comments :
Hey
Can you tell me ,after setting the year range, How to set a particular year in the Year_DropDownList. Like if i set yearRange :'1950:1994' , there i want 1994 to be selected ?.
Thanks
Hello
can you pls tell code for Datetime together in Web forms
Note: Only a member of this blog may post a comment.