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

Total Post:128

Points:898
Posted on    December-22-2014 10:40 PM

 ASP.Net C# 
Ratings:


 1 Reply(s)
 621  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 ?

Thanks

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

iCarId = Convert.ToInt32(myCarId);

Session["carId"] = iCarId;



Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
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