Click here to Skip to main content
16,021,288 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello.!!

I write this code but i get Error
"Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlInputHidden' to type 'System.IConvertible'."


anybody help me please?

protected void dgcategory_ItemDataBound(object sender, DataGridItemEventArgs e)
   {
       if (e.Item.ItemType == ListItemType.Header)
       {
           CheckBox chk = new CheckBox();
           chk = (CheckBox)e.Item.FindControl("chkHeader");
           chk.Attributes.Add("onclick", "javascript:return checkheader('chkHeader');");

           ImageButton imgtitle = new ImageButton();
           imgtitle = (ImageButton)e.Item.FindControl("imgasc");
           if (queryval.Value == "asc")
           {
               imgtitle.ImageUrl = "images/asc.png";
               imgtitle.ToolTip = "Ascending";
               imgtitle.AlternateText = "Ascending";
           }
           else
           {
               imgtitle.ImageUrl = "images/desc.png";
               imgtitle.ToolTip = "Descending";
               imgtitle.AlternateText = "Descending";
           }

           ImageButton imgtitle1 = new ImageButton();
           imgtitle1 = (ImageButton)e.Item.FindControl("imgasc1");
           if (queryval1.Value == "asc")
           {
               imgtitle1.ImageUrl = "images/asc.png";
               imgtitle1.ToolTip = "Ascending";
               imgtitle1.AlternateText = "Ascending";
           }
           else
           {
               imgtitle1.ImageUrl = "images/desc.png";
               imgtitle1.ToolTip = "Descending";
               imgtitle1.AlternateText = "Descending";
           }
       }
       if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
       {
           CheckBox chk = new CheckBox();
           chk = (CheckBox)e.Item.FindControl("chkDelete");
           chk.Attributes.Add("onclick", "javascript:return checkother('chkHeader');");

           if (Convert.ToBoolean((HtmlInputHidden)e.Item.FindControl("hiddisstatus")) == true)
           {
               ((LinkButton)e.Item.FindControl("disstatus")).Text = "Activate";
           }
           else
           {
               ((LinkButton)e.Item.FindControl("disstatus")).Text = "Deactivate";
           }
       }
   }


Thank you.
Posted
Updated 21-May-10 5:13am
v2

narendrarathod wrote:
if (Convert.ToBoolean((HtmlInputHidden)e.Item.FindControl("hiddisstatus")) == true)


What are you trying to do here?
You are converting a hidden variable to boolean, which is not at all possible so thats the error.
Get the value of the hidden variable and try
 
Share this answer
 
Comments
narendrarathod 21-May-10 9:43am    
Thank you to giving me respose but
i tried to get value from front end <asp:linkbutton id="disstatus" runat="server" cssclass="orange_h" commandname="cmddisstatus"> but i get error as i declared before if any other way so please tell me
narendrarathod wrote:
if (Convert.ToBoolean((HtmlInputHidden)e.Item.FindControl("hiddisstatus")) == true)


Try:
C#
if (Convert.ToBoolean(((HtmlInputHidden)e.Item.FindControl("hiddisstatus")).Value))
 
Share this answer
 
Comments
narendrarathod 22-May-10 3:10am    
Thank you .. afterthat i correct it ..
Sandeep was close, but I think he got a parentheses in the wrong spot. Actually, looking at it, he's correct. But he didn't explain what your problem was.

C#
e.Item.FindControl(NameOfControl)
returns a Control. A Control cannot be converted to a Boolean because they do not have an implicit conversion like the ToString() method. You need to actually access the value stored within the HtmlInputHidden object and convert that to a Boolean...assuming that you stored a Boolean value in it somewhere.

So, it should look like:
C#
if (Convert.ToBoolean(((HtmlInputHidden)e.Item.FindControl("hiddisstatus")).Value) == true)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900