Serenity
Serenity

Reputation: 5098

Need help with the format exception::Input string was not in a correct format

property in my mainClass

  public Int64 DetailID
        {
            get { return bintDetailID; }
            set { bintDetailID = value; }
        }

myClass

mainClass obj=new mainClass();
obj.DetailID = int.Parse(e.CommandArgument.ToString());

aspx page

<asp:Button ID="btnEdit" Text="Edit" CommandArgument='<%#Eval("DetailID") %>'
CausesValidation="false" CommandName="Edit" Visible="false" runat="server" OnCommand="btnEdit_Click"/>

Isn't this how u convert string to int ?

int.Parse(e.CommandArgument.ToString());

Whats wrong ? plz help..thnx

Upvotes: 1

Views: 1614

Answers (3)

Jagmag
Jagmag

Reputation: 10356

Assuming that your Button object is NOT within a databound control like a grid / repeater, AND If you are trying to Bind the button using the DetailID property, check the following:-

  1. Assuming your button is in testPage.aspx, the codebehind class for testPage.aspx i.e class testPage should have a property of type Int64 called DetailID. eg : Int64 DetailID get; set;

  2. Assuming mainClass is some custom class of yours, somewhere in Page_Load, you will have to do a this.DetailID = mainClassObject.DetailID; where this = instance of your page.

  3. In your page_load method, additionally, you will have to do a Page.DataBind(). This is because a non-databound control like button does not have its own DataBind() method.

Note 1: If your testPage.DetailID = Int32 / int, you will need to do the conversion in the setter method or before that as y0ur mainClass is an Int64

Note 2: From your comments, you seem to be saying that Int64 doesnt exist. Which is weird! Try using the fully qualified name i.e System.Int64 and see if that works!

Upvotes: 1

tsimbalar
tsimbalar

Reputation: 5990

Just to be sure, try setting the value for CommandArgument from the code-behind ...

btnEdit.CommandArgument = DetailID.ToString();

One doubt I have though, is if in your .aspx file you should write

CommandArgument='<%=Eval("DetailID") %>'

instead of

CommandArgument='<%#Eval("DetailID") %>'

(note the = vs #)

Upvotes: 0

PrateekSaluja
PrateekSaluja

Reputation: 14926

Int.parse is used to covert into 32 bit integer value.According to your question

 public Int64 DetailID
        {
            get { return bintDetailID; }
            set { bintDetailID = value; }
        }

Its 64 bit.

try Int64.parse(e.CommandArgument.ToString());

if you are getting empty value check

 (!string.IsNullOrEmpty(e.CommandArgument.ToString())
Int64.parse(e.CommandArgument.ToString());

Hope it works.

Thanks

Upvotes: 4

Related Questions