Skip to main content
added 1106 characters in body
Source Link
Diptarag
  • 1.7k
  • 1
  • 12
  • 21

I guess this line is throwing error for your case in SearchList.cs-

public decimal ListPrice
{
    get
    {
        if (_listPrice != null)
            return ((SearchListUserControl)_listPrice).ListPrice;
        ***return decimal.Parse(string.Empty);***
    }
}

change return decimal.Parse(string.Empty), it will never work, change it to return decimal.MinValue instead, and add some checking when you use the value


Though I dont get what you are trying to achieve with this method, but you can use TryParse to distinguish between pure string and number, may be like this -

    public void SetProduct(string product)
    {
        decimal ListPrice;
        if(decimal.TryParse(product, out ListPrice)
        {
            TextBox_ListPriceList.Text="ListPrice";
        }
        else
        {
            if (product == "ProductNumber")
            {
                TextBox_ProdNumList.Text = "ProductNumber";
            }            
            else if (product == "Color")
            {
                TextBox_ColorList.Text = "Color";
            }
            else if (product == "Name")
            {
                TextBox_NameList.Text = "Name";
            }
            else if (product == "MoreInformation")
            {
                TextBox_MoreInfoList.Text = "MoreInformation";
            }
        }            
    }

I guess this line is throwing error for your case in SearchList.cs-

public decimal ListPrice
{
    get
    {
        if (_listPrice != null)
            return ((SearchListUserControl)_listPrice).ListPrice;
        ***return decimal.Parse(string.Empty);***
    }
}

change return decimal.Parse(string.Empty), it will never work, change it to return decimal.MinValue instead, and add some checking when you use the value

I guess this line is throwing error for your case in SearchList.cs-

public decimal ListPrice
{
    get
    {
        if (_listPrice != null)
            return ((SearchListUserControl)_listPrice).ListPrice;
        ***return decimal.Parse(string.Empty);***
    }
}

change return decimal.Parse(string.Empty), it will never work, change it to return decimal.MinValue instead, and add some checking when you use the value


Though I dont get what you are trying to achieve with this method, but you can use TryParse to distinguish between pure string and number, may be like this -

    public void SetProduct(string product)
    {
        decimal ListPrice;
        if(decimal.TryParse(product, out ListPrice)
        {
            TextBox_ListPriceList.Text="ListPrice";
        }
        else
        {
            if (product == "ProductNumber")
            {
                TextBox_ProdNumList.Text = "ProductNumber";
            }            
            else if (product == "Color")
            {
                TextBox_ColorList.Text = "Color";
            }
            else if (product == "Name")
            {
                TextBox_NameList.Text = "Name";
            }
            else if (product == "MoreInformation")
            {
                TextBox_MoreInfoList.Text = "MoreInformation";
            }
        }            
    }
Source Link
Diptarag
  • 1.7k
  • 1
  • 12
  • 21

I guess this line is throwing error for your case in SearchList.cs-

public decimal ListPrice
{
    get
    {
        if (_listPrice != null)
            return ((SearchListUserControl)_listPrice).ListPrice;
        ***return decimal.Parse(string.Empty);***
    }
}

change return decimal.Parse(string.Empty), it will never work, change it to return decimal.MinValue instead, and add some checking when you use the value