0
votes

I am trying to convert two string values to integers, and multiply them, to use in a ListView on an ASPX page.

The following code doesn't work, but it should give you an idea of what I am trying to accomplish:

<%#String.Format("{0:c}", Convert.ToInt32(Eval("nbrQtyOrdered")) * Convert.ToInt32(Eval("curSellPrice"))) %>

I am getting the following error:

An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code

Additional information: Input string was not in a correct format.

nbrQtyOrdered is a string representation of an integer value and curSellPrice is a string representation of a double written as "$22.22", for example. I am assuming now the dollar sign is giving me the error.

How can I fix this problem and achieve what I am trying to do?

1
What is the issue you are having? What have you tried? What error(s) are you getting?MaCron
@MaCron An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code Additional information: Input string was not in a correct format.cjtampa
what are your input values? have you tried debugging this to make sure everything is what you think it should be?MaCron

1 Answers

0
votes

You are correct. "$22.22" with a dollar sign cannot be converted to an Integer.

I would suggest first trimming the dollar sign. This can be done multiple ways:

Eval("curSellPrice").Replace("$", "")

OR

Eval("curSellPrice").TrimStart('$');

Once you remove the dollar sign from the curSellPrice string, you should be able to use it with Convert.ToInt32() .