Hemanth
Hemanth

Reputation: 413

rangevalidator for textbox for max & min date is not working?

I am using following code in page load but it give Error:

Cannot implicitly convert type System.DateTime to string

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

Answers (1)

Akram Shahda
Akram Shahda

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

Related Questions