ASP.NET Decimal.Parse()
<p>I have problem in webpage , Visual Studio claims that problem is with this line <code>decimal newAmount = PLNamount * Decimal.Parse(item.Value);</code>. The solution is crushed when I choose the Current (web page is simple current converter) .</p>

<p>this is listing of CurrencyConverter.aspx.cs</p>

<pre><code>using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public partial class CurrencyConverter : System.Web.UI.Page
{
    protected void Page_Load(Object sender, EventArgs e)
    {
        if (this.IsPostBack == false)
        {
            // The HtmlSelect control accepts text or ListItem objects.
            Currency.Items.Add(new ListItem("Euros", "0.25"));
            Currency.Items.Add(new ListItem("US Dollar", "0.32"));
            Currency.Items.Add(new ListItem("British Pound", "0.205"));
        }
    }
    protected void Convert_ServerClick(object sender, EventArgs e)
    {

        decimal PLNamount;

        bool success = Decimal.TryParse(PLN.Value,out PLNamount);
        if (success)
        {
            PLNamount = Decimal.Parse(PLN.Value);
            ListItem item = Currency.Items[Currency.SelectedIndex];
            decimal newAmount = PLNamount * Decimal.Parse(item.Value); //prollematic line

            Result.InnerText = PLNamount.ToString() + " Polish PLN = ";
            Result.InnerText += newAmount.ToString() + " " + item.Text;
        }
        else Result.InnerText = "Invalid content";
    }
}
</code></pre>

<p>This is listing of CurrencyConverter.aspx</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true"
CodeFile="CurrencyConverter.aspx.cs" Inherits="CurrencyConverter" %&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;title&gt;Currency Converter&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
Simple Currency Converter in ASP.NET web forms &lt;br /&gt;

&lt;form id="Form1" runat="server"&gt;
&lt;div&gt;
Convert: &amp;nbsp;
&lt;input type="text" ID="PLN" runat="server" /&gt;
&amp;nbsp; Polish PLN to Euros.
&lt;select ID="Currency" runat="server" /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;input type="submit" value="OK" ID="Convert" runat="server"
OnServerClick="Convert_ServerClick" /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;div style="font-weight: bold" ID="Result" runat="server"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>This Code is changed listing from apress "Pro ASP.NET 3.5 in C# 2008, Second Edition" (original version) from chapter 5. Link to source code apress.com/book/downloadfile/3803 . I have exactly the same problem in the same line</p>

<p>Original source code from the book</p>

<p>*aspx
&lt;%@ Page Language="C#" AutoEventWireup="true"
    CodeFile="CurrencyConverter.aspx.cs" Inherits="CurrencyConverter" %></p>

<p></p>

<p>
  
    Currency Converter
  
  
    </p>

<pre><code>    &lt;div style="border-right: thin ridge; padding-right: 20px; border-top: thin ridge;
        padding-left: 20px; padding-bottom: 20px; border-left: thin ridge; width: 531px;
        padding-top: 20px; border-bottom: thin ridge; font-family: Verdana; background-color: #FFFFE8"&gt;
    Convert: &amp;nbsp;
    &lt;input type="text" ID="US" runat="server" style="width: 102px" /&gt;&amp;nbsp; U.S. dollars to &amp;nbsp;
    &lt;select ID="Currency" runat="server" /&gt;
    &lt;br /&gt;&lt;br /&gt;
    &lt;input type="submit" value="OK" ID="Convert" runat="server" OnServerClick="Convert_ServerClick" /&gt;
    &lt;input type="submit" value="Show Graph" ID="ShowGraph" runat="server" OnServerClick="ShowGraph_ServerClick" /&gt;
    &lt;br /&gt;&lt;br /&gt;
    &lt;img ID="Graph" alt="Currency Graph" scr="" runat="server" /&gt;
    &lt;br /&gt;&lt;br /&gt;
    &lt;div style="font-weight: bold" ID="Result" runat="server"&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/form&gt;
</code></pre>

<p>
</p>

<p>*aspx.cs</p>

<p>using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;</p>

<p>public partial class CurrencyConverter : System.Web.UI.Page
{
    protected void Page_Load(Object sender, EventArgs e)
    {
        if (this.IsPostBack == false)
        {
            // The HtmlSelect control accepts text or ListItem objects.
            Currency.Items.Add(new ListItem("Euros", "0.85"));
            Currency.Items.Add(new ListItem("Japanese Yen", "110.33"));
            Currency.Items.Add(new ListItem("Canadian Dollars", "1.2"));
        }
        Graph.Visible = false;
    }
    protected void Convert_ServerClick(object sender, EventArgs e)
    {
        decimal amount;
        bool success = Decimal.TryParse(US.Value, out amount);
        if (success)
        {
            // Retrieve the selected ListItem object by its index number.
            ListItem item = Currency.Items[Currency.SelectedIndex];</p>

<pre><code>        decimal newAmount = amount * Decimal.Parse(item.Value);
        Result.InnerText = amount.ToString() + " U.S. dollars = ";
        Result.InnerText += newAmount.ToString() + " " + item.Text;
    }
    else
    {
        Result.InnerText = "The number you typed in was not in the correct format. ";
        Result.InnerText += "Use only numbers.";
    }
}

protected void ShowGraph_ServerClick(object sender, EventArgs e)
{
    Graph.Src = "Pic" + Currency.SelectedIndex.ToString() + ".png";
    Graph.Visible = true;
}
</code></pre>

<p>}</p>

<p>Problem solved</p>

<p>This is link to print screen with this error. <a href="http://img210.imageshack.us/f/currencyerror.png/" rel="nofollow">http://img210.imageshack.us/f/currencyerror.png/</a></p>
