我正在研究在网格视图上动态创建的Startdate和enddate Textbox的需求。当点击开始日期和结束日期时,datepicker必须打开.for结束日期,它必须根据startdate禁用日期。它在gridview之外工作正常。;
<script type="text/javascript">
$(document).ready(function () {
$("#<%=txtStartTime.ClientID%>").datepicker({
changeMonth: true,
changeYear: true,
minDate: 0,
maxDate: "+365D",
onSelect: function () {
var minFromDate = $(this).datepicker('getDate');
$("#<%=txtEndTime.ClientID%>").datepicker("option", "minDate", minFromDate); //dates less than the selected from date will be disabled in "txtToDate" textbox
var maxToDate = "+3Y";
$("#<%=txtEndTime.ClientID%>").datepicker("option", "maxDate", maxToDate) //maxToDate set to 3 years from FromDate
},
onClose: function (dateText, inst) {
var validDate = $.datepicker.formatDate("yy-mm-dd", $("#<%=txtStartTime.ClientID%>").datepicker('getDate'));
$("#<%=txtStartTime.ClientID%>").datepicker('setDate', validDate);
},
dateFormat: "yy-mm-dd"
}, "showAnim", $(this).val());
$("#<%=txtEndTime.ClientID%>").datepicker({
changeMonth: true,
changeYear: true,
minDate: 0, // '0' means current date
maxDate: "+5Y",
onSelect: function () {
var maxToDate = $(this).datepicker('getDate');
$("#<%=txtStartTime.ClientID%>").datepicker("option", "maxDate", maxToDate) //set the "MaxDate" attribute for "txtFromDate" in onSelect event of "txtToDate" textbox
},
onClose: function (dateText, inst) {
var validDate = $.datepicker.formatDate("yy-mm-dd", $("#<%=txtEndTime.ClientID%>").datepicker('getDate'));
$("#<%=txtEndTime.ClientID%>").datepicker('setDate', validDate);
},
dateFormat: "yy-mm-dd"
}, "showAnim", $(this).val());
});
</script>
动态创建的Textbox ID如下所示
D3Step1_gridview__ctl2_txtStartDate D3Step1_gridview__ctl2_txtEndDate
D3Step1_gridview__ctl3_txtStartDate D3Step1_gridview__ctl3_txtEndDate