Vishnu
Vishnu

Reputation: 33

Unable to cast object of type 'System.Web.UI.WebControls.ImageButton' to type 'System.Web.UI.WebControls.LinkButton'

I am casting one Image Button to a Link Button. But I'm getting the error: "Unable to Cast object of type Image Button to type LinkButton."

I am stuck, please guys help me out.

My Code :

LinkButton lnkbtnresult = (LinkButton)e.Row.FindControl("Imgresult");

Upvotes: 1

Views: 3672

Answers (1)

Adil
Adil

Reputation: 148150

Use ImageButton instead of LinkButton as you can not cast ImageButton to LinkButton

ImageButton imgbtnresult = (ImageButton)e.Row.FindControl("Imgresult");

Once you have ImageButton, you can use its properties to assign to LinkButton object if really required.

LinkButton lnkButton = new LinkButton();
lnkButton.SomeProperty = imgbtnresult.SomeProperty;

Upvotes: 1

Related Questions