[英]How to set RaddatePicker Min Date and Max Date Based on Financial Year in C# Coding?
I am using ASP RadControls for my project. 我正在为我的项目使用ASP RadControls。 I want to know how to set MinDate and MaxDate based on the Financial Year. 我想知道如何根据财政年度设置MinDate和MaxDate。 I try following code but I am not getting how set min value and max value to datepicker. 我尝试下面的代码,但我没有得到如何设置最小值和最大值为datepicker。 Kindly help me. 请帮助我。
string finyear = ViewState["FIN_YR"].ToString();//viewstate["FIN_YR"]="1112"
string pr = finyear.Substring(0, 2);//pr="11"
string pr1 = "20";
string year1 =pr1+pr;//year1="2011"
int firstyear = Convert.ToInt32(year1);
string pa = finyear.Substring(2, 2);//pa="12"
string year2 = pr1 + pa;//year2="2012"
int Secondyear = Convert.ToInt32(year2);
dtpRemitDate.MinDate = System.DateTime.Parse("firstyear/4/1");
I tried like this but System.DateTime.Parse("int,int,int");
我试过这样但是System.DateTime.Parse("int,int,int");
only acceptable. 只接受。 How can I set min Date to datepicker? 如何将min Date设置为datepicker?
To start with, I would try to form far fewer string operations. 首先,我会尝试,形成少得多的字符串操作。 It looks like you only need two: 看起来你只需要两个:
Do the rest based on DateTime
and int
: 其余的基于DateTime
和int
:
string financialYearText = ViewState["FIN_YR"].ToString();
int minYear2Digits = int.Parse(financialYearText.Substring(0, 2));
int maxYear2Digits = int.Parse(financialYearText.Substring(2, 2));
dtpRemitDate.MinDate = new DateTime(minYear2Digits + 2000, 4, 1);
dtpRemitDate.MaxDate = new DateTime(maxYear2Digits + 2000, 4, 1);
This assumes it will always be based on the year 2000 - if you have "old" records eg "8788" which should mean 1987 and 1988, you'd need to do a bit more work. 这假设它总是基于2000年 - 如果你有“旧”记录,例如“8788”,这应该意味着1987年和1988年,你需要做更多的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.