Akhter HUssain

Akhter HUssain

  • 685
  • 1.3k
  • 95.5k

How to Retrieve null datetime in a texbox from gridview ?

Sep 11 2019 3:43 AM
i am selection row from gridview in which leftdate is not available/empty ,so when i select that row editing then exception is raised that (String was not recognized as a valid DateTime.')
here is screen shot 
 
here c# code 
 
  1. protected void Edit(object sender, EventArgs e)  
  2.         {  
  3.             using (GridViewRow row = (GridViewRow)((LinkButton)sender).Parent.Parent)  
  4.             {  
  5.                 txtEmpID.ReadOnly = true;  
  6.                 txtEmpID.Text = row.Cells[0].Text;  
  7.                 txtEmpName.Text = row.Cells[1].Text;  
  8.                 txtFahterName.Text = row.Cells[2].Text;  
  9.                 //ddlSecID.ClearSelection();  
  10.                 //ddlSecID.Items.FindByText(row.Cells[3].Text).Selected = true;  
  11.                 //txtjdate.Text = row.Cells[4].Text;  
  12.                 txtCNIC.Text = row.Cells[3].Text;  
  13.                 ddlSecID.ClearSelection();  
  14.                 if (ddlSecID.Items.FindByText(row.Cells[4].Text) != null)  
  15.                 {  
  16.                     ddlSecID.Items.FindByText(row.Cells[4].Text).Selected = true;  
  17.                 }  
  18.                 if (ddlstatus.Items.FindByText(row.Cells[5].Text) != null)  
  19.                 {  
  20.                     ddlstatus.Items.FindByText(row.Cells[5].Text).Selected = true;  
  21.                 }  
  22.                 txtjdate.Text = Convert.ToDateTime(row.Cells[6].Text).ToString("dd/MM/yyyy");  
  23.                 
  24.                  
  25.   
  26.                 if (!string.IsNullOrEmpty(txtldate.Text))  
  27.                 {  
  28.                     //   DateTime date = DateTime.Parse(txtldate.Text);  
  29.                     txtldate.Text = null;  
  30.                 }  
  31.                 else  
  32.                 {  
  33.                     txtldate.Text = Convert.ToDateTime(row.Cells[7].Text).ToString("dd/MM/yyyy");  
  34.                 }  
  35.   
  36.                 popup.Show();  
  37.             }  
  38.         }  

Answers (26)