Search code examples
asp.netvb.nettextboxdecimal-point

Incorrect decimal point position


I have a text box into which I want to input values in a format such as "1.5" and when I type "1.5" into the text box "15.00" is saved to my database. The value shall accept both commas and decimals from the user, but the position of the decimal point needs to be after the first digit (1.5) and the seperator displayed on the GridView needs to be the dot but it displays the comma.

Here is my textbox.

<asp:TextBox ID="txtCase" runat="server" Width="90px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvCase" runat="server" ControlToValidate="txtCase"
    ErrorMessage="Required" ForeColor="Red" Display="Dynamic" ValidationGroup="Insert"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revCase" runat="server" ErrorMessage="Decimal Field"
    ControlToValidate="txtCase" ForeColor="Red" ValidationExpression="^\d+([,\.]\d{1,2})?$"></asp:RegularExpressionValidator>

I have tried:

how to decrease decimal places in gridview column asp.net C#

format a number with commas and decimals in C# (asp.net MVC3) (This is C# but I prefer using my .aspx file).

I have also tried adding these to my text box.

DataFormatString="{0:0.00}"
DataFormatString="{0:0.0}"

but unfortunately no luck.

I'm not sure on what else I can change and most articles I've found off Stack Overflow are about what comes after the decimal point.

So in a nutshell, I need 1.5 to be inserted instead of 15.00 and I need my GridView to show the dot instead of the comma as the seperator.

GridView column

<asp:BoundField DataField="Cases" SortExpression="Cases" HeaderText="Cases" Visible="true"
 ReadOnly="true" ItemStyle-HorizontalAlign="Center"/>

Any ideas?


Solution

  • Added

    Culture="en-US"
    

    Into the

    <%@ Page
    

    of the .aspx file.