Click here to Skip to main content
15,906,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all

i need to check that if date of birth is less than 30/11/2007 than i need to disable some textbox.
here is my code i trying


if (dtdates.Rows[0]["dob"].ToString() < "30/11/2007")  //if dob is before 30/11/2007 than disabling
                  {
                      Txt1.Enabled = false;
                      Txt2 = false;
                      Txt2 = false;

                  }

cannot be applied to operands of type < string and string
Posted

1 solution

Do date comparison instead of string comparison.

Try something like:
C#
if (Convert.ToDate(dtdates.Rows[0]["dob"]) < Convert.ToDate("30/11/2007"))  //if dob is before 30/11/2007 than disabling 
{
                        Txt1.Enabled = false;
                        Txt2 = false;
                        Txt2 = false;
 
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-May-12 1:28am    
Endless misconception... My 5 for answering.
--SA
Sandeep Mewara 2-May-12 2:33am    
Thanks SA.
balongi 2-May-12 2:35am    
how it achieve in javascript ?
Sandeep Mewara 2-May-12 3:18am    
In Javascript: There is 'Date' object instead of DateTime.

Date someDate = new Date("1/1/2011");

Use similar logic based on the event and values you have. Do the date comparison.
balongi 2-May-12 4:29am    
it say ; missing before statment

Date someDate = new Date("1/1/2011");
.......; missing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900