ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.ASP.Net GridView RowDataBound Error: String was not recognized as a valid DateTime<p>Hi&nbsp;akhter,</p> <p>You need to check IsNullOrEmpty condition to avoid the error.</p> <pre class="brush: csharp">if (e.Row.RowType == DataControlRowType.DataRow) { TextBox txtEntryDate = e.Row.FindControl(&#34;txtEntryDate&#34;) as TextBox; TextBox txtEndDate = e.Row.FindControl(&#34;txtEndDate&#34;) as TextBox; if (!string.IsNullOrEmpty(txtEntryDate.Text) &amp;&amp; !string.IsNullOrEmpty(txtEndDate.Text)) { DateTime startDate = Convert.ToDateTime(txtEntryDate.Text); DateTime endDate = Convert.ToDateTime(txtEndDate.Text); TextBox txtHours = e.Row.FindControl(&#34;txtHours&#34;) as TextBox; TextBox txtDays = e.Row.FindControl(&#34;txtDays&#34;) as TextBox; txtHours.Text = endDate.Subtract(startDate).Hours.ToString(); txtDays.Text = endDate.Subtract(startDate).Days.ToString(); } }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/196050/ASPNet-GridView-RowDataBound-Error-String-was-not-recognized-as-a-valid-DateTime/https://www.aspforums.net:443/Threads/196050/ASPNet-GridView-RowDataBound-Error-String-was-not-recognized-as-a-valid-DateTime/Fri, 28 Dec 2018 04:03:42 GMTASP.Net GridView RowDataBound Error: String was not recognized as a valid DateTime<p>Hi&nbsp;akhter,</p> <p>Same way you can check with IsNullOrEmpty condition in TimeSpan to avoid the error.</p> <pre class="brush: csharp">protected void TimeSpan(object sender, EventArgs e) { GridViewRow row = (sender as TextBox).NamingContainer as GridViewRow; string txtINTIME = (row.FindControl(&#34;txtINTIME &#34;) as TextBox).Text; string txtTime = (row.FindControl(&#34;txtTime&#34;) as TextBox).Text; if (!string.IsNullOrEmpty(txtINTIME) &amp;&amp; !string.IsNullOrEmpty(txtTime)) { TimeSpan timeSpan = Convert.ToDateTime(txtTime) - Convert.ToDateTime(txtINTIME); } }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/196050/ASPNet-GridView-RowDataBound-Error-String-was-not-recognized-as-a-valid-DateTime/https://www.aspforums.net:443/Threads/196050/ASPNet-GridView-RowDataBound-Error-String-was-not-recognized-as-a-valid-DateTime/Fri, 28 Dec 2018 05:07:51 GMT