Hi
I am getting error - Unable to cast object of type 'System.Web.UI.WebControls.HiddenField' to type 'System.IConvertible'.
HiddenField hdfDate = ((HiddenField)e.Item.FindControl("hdfDate"));
Thanks
Hi
I am getting error - Unable to cast object of type 'System.Web.UI.WebControls.HiddenField' to type 'System.IConvertible'.
HiddenField hdfDate = ((HiddenField)e.Item.FindControl("hdfDate"));
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vishal JoshiPosted May 30, 2023, 5:31 AM
Hello Ramco
Please try DateTime.Compare() to get the expected result.
Ramco RamcoPosted May 28, 2023, 4:58 PM
Hi Mohammed
I am getting error on below line. Valie in hdfDate is "03/06/2023 00:00:00"
Value in GrpSessionStartDate is 20/05/2023 00:00:00
When i try below line then also gets error -
DateTime sDate = DateTime.ParseExact(hdfDate.Value, "yyyy/MM/dd HH:mm:ss",
CultureInfo.InvariantCulture);
Thanks
Mohamed Azarudeen ZPosted May 28, 2023, 4:49 PM
Hi ramco
You can modify your code as follows:
By using the
askeyword, you attempt to perform the cast, and if the cast fails, the variablehdfDatewill be assigned a null value instead of throwing an exception.Make sure to update your code accordingly and try running it again. This should resolve the casting issue you're experiencing.