locked
Error - Input string was not in correct format RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I am getting above error on below line . No is int type field.

    Int32 hdfNo = Convert.ToInt32(((HiddenField)row.FindControl("hdfNo")).Value);

    <asp:TemplateField Visible = "false">
                                            <ItemTemplate>
                                                
                                                <asp:HiddenField ID="hdfNo" runat="server" Value='<%# Eval("No") %>' />
                                            </ItemTemplate>
                                        </asp:TemplateField>

    Thanks

    Monday, August 6, 2018 2:14 PM

All replies

  • User753101303 posted

    Hi,

    It means the string couldn't be converted. When it happens have a look at the value you are trying to convert from ie here see which vlaue is stored in ((HiddenField)row.FindControl("hdfNo")).Value

    Monday, August 6, 2018 2:24 PM
  • User-1171043462 posted
    1. Add a BreakPoint and check the value of HiddenField.
    2.  Add Trim at end as it could be possible White space

    Int32 hdfNo = Convert.ToInt32((row.FindControl("hdfNo") as HiddenField).Value.Trim());

    Monday, August 6, 2018 6:29 PM