---
title: "conversion issue from a Label to int for an ID key"  
description: "conversion issue from a Label to int for an ID key"  
author: "Anonymous User"  
published: 2014-12-22  
updated: 2014-12-23  
canonical: https://www.mindstick.com/forum/12806/conversion-issue-from-a-label-to-int-for-an-id-key  
category: "asp.net"  
tags: ["c#"]  
reading_time: 1 minute  

---

# conversion issue from a Label to int for an ID key

I got [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) converting this car id key from a [label](https://www.mindstick.com/articles/12835/print-label-tracking-how-do-these-features-make-auspost-woocommerce-plugin-better). Here is the [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) I am receiving

[Unable to cast object](https://answers.mindstick.com/qa/100480/unable-to-cast-object-of-type-dbcontext-models-users-to-type-iobjectcontextadapter) of type 'System.Web.UI.WebControls.HiddenField' to type 'System.Web.UI.WebControls.Label'.

Do you have any suggestion to [avoid](https://yourviews.mindstick.com/story/1518/tips-to-avoid-dengue-at-home) this error ?

Thanks

Label myCarId = (Label)item.FindControl("carId");

iCarId = Convert.ToInt32(myCarId);

[Session](https://www.mindstick.com/articles/12042/session-in-c-sharp)["carId"] = iCarId;

## Replies

### Reply by Manoj Bhatt

It should be:

```
HiddenField myCarId = (HiddenField)item.FindControl("carId");iCarId = Convert.ToInt32(myCarId.Value);Session["carId"] = iCarId;
```


---

Original Source: https://www.mindstick.com/forum/12806/conversion-issue-from-a-label-to-int-for-an-id-key

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
