Reputation: 413
I am using following code in page load but it give Error:
Cannot implicitly convert type
System.DateTime
tostring
so i have change RangeValidators type to string; but its not working, I want that textbox should contain date between max & min value specified at runtime?
yr1 =Convert.ToString(Session["FYear"]);
yr=yr1.Split('-');
startyr = yr[0].ToString();
endyr = yr[1].ToString();
dt1 = "01/04/" + startyr;
dt2 = "31/03/" + endyr;
RangeValidator1.MinimumValue =Convert.ToDateTime(dt1);
RangeValidator1.MaximumValue = Convert.ToDateTime(dt2);
Upvotes: 1
Views: 2223
Reputation: 14781
RangeValidator
's MinimumValue
and MaximumValue
are of the type System.String
. That's why you are getting the error.
Edit your code:
RangeValidator1.MinimumValue = dt1;
RangeValidator1.MaximumValue = dt2;
Read about RangeValidator
Upvotes: 2