ASP .NET Binding with Format {0:N0} is one way only

  • Thread starter Thread starter jehugaleahsa
  • Start date Start date
J

jehugaleahsa

Hello:

I am working on an ASP .NET page and I have a integral value being
bound to a textbox.

I have it formatted with {0:N0} so that I get commas, but not decimal
places. When I go to update, I get an 'Input String not in the correct
format' error. I am not sure why it is okay for interface to correctly
display my data, but then not be able to update.

What is the fix?

Thanks,
Travis
 
try

public static decimal ToDecimal(string value)
{
if (value == null || value.Length == 0)
return 0;
if (value == null)
throw new ArgumentNullException("value");
return Decimal.Parse(value.Replace(" ", ""), NumberStyles.AllowThousands |
NumberStyles.AllowDecimalPoint | NumberStyles.AllowCurrencySymbol,
CultureInfo.CurrentCulture);
}
 
try

public static decimal ToDecimal(string value)
{
  if (value == null || value.Length == 0)
    return 0;
  if (value == null)
    throw new ArgumentNullException("value");
  return Decimal.Parse(value.Replace(" ", ""), NumberStyles.AllowThousands |
NumberStyles.AllowDecimalPoint | NumberStyles.AllowCurrencySymbol,
CultureInfo.CurrentCulture);

}

--
Misbah Arefinhttps://mcp.support.microsoft.com/profile/MISBAH.AREFINhttp://www.linkedin.com/in/misbaharefin









- Show quoted text -

That comes with too much work for something that should be built in.
 
try

public static decimal ToDecimal(string value)
{
  if (value == null || value.Length == 0)
    return 0;
  if (value == null)
    throw new ArgumentNullException("value");
  return Decimal.Parse(value.Replace(" ", ""), NumberStyles.AllowThousands |
NumberStyles.AllowDecimalPoint | NumberStyles.AllowCurrencySymbol,
CultureInfo.CurrentCulture);

}

--
Misbah Arefinhttps://mcp.support.microsoft.com/profile/MISBAH.AREFINhttp://www.linkedin.com/in/misbaharefin









- Show quoted text -

I did what you said with the FormView and GridView Updating and
Inserting event handlers. I'm not too happy about it. I'm going to go
boil my head.
 
try

public static decimal ToDecimal(string value)
{
  if (value == null || value.Length == 0)
    return 0;
  if (value == null)
    throw new ArgumentNullException("value");
  return Decimal.Parse(value.Replace(" ", ""), NumberStyles.AllowThousands |
NumberStyles.AllowDecimalPoint | NumberStyles.AllowCurrencySymbol,
CultureInfo.CurrentCulture);

}

--
Misbah Arefinhttps://mcp.support.microsoft.com/profile/MISBAH.AREFINhttp://www.linkedin.com/in/misbaharefin









- Show quoted text -

Oh, and thanks.
 
Back
Top