troubleshooting Question

Details view - Input string was not in a correct format

Avatar of Simon Cripps
Simon CrippsFlag for United Kingdom of Great Britain and Northern Ireland asked on
ASP.NET
4 Comments1 Solution865 ViewsLast Modified:
I have a details view on my webpage and this was happily storing the data that I was placing in it. However one of the fields was not storing any decimal places. As I wanted to store decimal places for the field, I changed the database field from type int to type Decimal(10,2) to allow for 2 decimal place. I can type the values with decimal places direct into the cell in the database, but when I try to update with the details view I get a "Input string was not in a correct format" error.
The field is set as a template field and there is no coding behind this bar the expression validator.

How can I resolve this?
<asp:TemplateField HeaderText="DiscountPercentage" 
                SortExpression="DiscountPercentage">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" 
                        Text='<%# Bind("DiscountPercentage") %>'></asp:TextBox>
                        <asp:RegularExpressionValidator ID="RequiredFieldValidator4"  ControlToValidate="TextBox3" runat="server" ErrorMessage="Percentage discount required" ValidationExpression="^(100(?:\.0{1,2})?|0*?\.\d{1,2}|\d{1,2}(?:\.\d{1,2})?)$"></asp:RegularExpressionValidator>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" 
                        Text='<%# Bind("DiscountPercentage") %>'></asp:TextBox>
                        <asp:RegularExpressionValidator ID="RequiredFieldValidator4"  ControlToValidate="TextBox3" runat="server" ErrorMessage="Percentage discount required" ValidationExpression="^(100(?:\.0{1,2})?|0*?\.\d{1,2}|\d{1,2}(?:\.\d{1,2})?)$"></asp:RegularExpressionValidator>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" 
                        Text='<%# Bind("VCDiscountPercentage") %>'></asp:Label>
                                                 
                </ItemTemplate>
            </asp:TemplateField>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros