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

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
 
M

Misbah Arefin

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);
}
 
J

jehugaleahsa

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.
 
J

jehugaleahsa

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.
 
J

jehugaleahsa

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top