conversion issue from a Label to int for an ID key

Total Post:128

Points:898

C# 
 1373  View(s)
Ratings:
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;

  1. Re: conversion issue from a Label to int for an ID key

    It should be:

    HiddenField myCarId = (HiddenField)item.FindControl("carId");
    iCarId = Convert.ToInt32(myCarId.Value);
    Session["carId"] = iCarId;

      Modified On Apr-07-2018 05:35:52 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.