how to solve date string not in correct format

Jul 12 2018 5:19 AM
  1. protected void btnUpdate_Click1(object sender, EventArgs e)  
  2.     {  
  3.         //TextBox txtISIN = (TextBox)grdLabEntry.Rows[0].FindControl("txtISINNumber");  
  4.         TextBox txtGrade = (TextBox)grdLabEntry.Rows[0].FindControl("txtGrade");  
  5.         TextBox txtValidity = (TextBox)grdLabEntry.Rows[0].FindControl("txtValidity");  
  6.         TextBox txtFED = (TextBox)grdLabEntry.Rows[0].FindControl("txtFED");  
  7.   
  8.   
  9.         //DMatEntry obj = new DMatEntry();  
  10.         SpotEntry obj = new SpotEntry();  
  11.         obj.SpotEntryId = RId;  
  12.         //obj.ISINNumber = txtISIN.Text;  
  13.         obj.Grade = txtGrade.Text;  
  14.         obj.Validity = Convert.ToDateTime(txtValidity.Text);  
  15.         obj.FEd = Convert.ToDateTime(txtFED.Text);  
  16.   
  17.         int result = SpotEntry.UpdateLabEntry(obj);  
  18.         if (result > 0)  
  19.         {  
  20.             grdLabEntry.EditIndex = -1;  
  21.   
  22.             obj.SpotEntryId = RId;  
  23.             DataTable dt = SpotEntry.GetAllDmatRecordsById(obj);  
  24.             if (dt.Rows.Count > 0)  
  25.             {  
  26.                 showmsg("Dmat Lab Entry Updated Successfully.");  
  27.                 grdLabEntry.DataSource = dt;  
  28.                 grdLabEntry.DataBind();  
  29.             }  
  30.         }  
how to solve date string is not recognize as a valid date.
actully when insert date it take  dd/mm/yyyy but when i select date greater then 12 it throw error date string not valid date because it understand dd /mm/yyyy to  mm/dd/yyyy
 so what can i do to solve this.
 
above is my code which i add in aspx file 
 
 

Answers (8)