Home > DeveloperSection > Forums > conversion issue from a Label to int for an ID key
Ashish Pandey

Total Post:128

Posted on    December-22-2014 10:40 PM

 ASP.Net C# 

 1 Reply(s)
 587  View(s)
Rate this:

I got problem converting this car id key from a label. Here is the error I am receiving

Unable to cast object of type 'System.Web.UI.WebControls.HiddenField' to type 'System.Web.UI.WebControls.Label'.

Do you have any suggestion to avoid this error ?


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

iCarId = Convert.ToInt32(myCarId);

Session["carId"] = iCarId;

Manoj Bhatt
Manoj Bhatt

Total Post:153

Posted on    December-23-2014 5:22 AM

It should be:

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

iCarId = Convert.ToInt32(myCarId.Value);

Session["carId"] = iCarId;

Don't want to miss updates? Please click the below button!

Follow MindStick