gpt4 book ai didi

c# - ASP.NET GridView 删除 'Input string was not in a correct format'

转载 作者:太空宇宙 更新时间:2023-11-03 13:10:20 24 4
gpt4 key购买 nike

我有一个 ASP.NET GridView,它显示我的数据库中的服装产品。我的数据库中的一个字段是 Price,为了将其显示为 £xxx.xx,我将 Price DataFormatString 设置为 {0:C}。

GridView 还有一个删除按钮,我已将其转换为模板并添加

OnClientClick="return confirm('Are you sure you want to delete this product?');"

单击按钮后添加确认消息。但是,当我单击“确定”确认删除产品时,我收到此错误消息:

Input string was not in a correct format.

当我从 GridView 中取出 DataFormatString 以便价格显示为默认的 xxx.xxxx 时,删除功能工作正常。只有当存在 DataFormatString 时,我才会收到此错误。我该如何解决这个问题?感谢帮助。

HTML

<div id="GridView">
<asp:GridView ID="ProductsGridView" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellSpacing="-1" DataKeyNames="Id" DataSourceID="ProductsGridView_DS" GridLines="None" CssClass="ProductsGrid" AlternatingRowStyle-CssClass="alt">
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Select" Text="Select"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this product?');"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" DataFormatString="{0:C}" />
<asp:CheckBoxField DataField="Available" HeaderText="Available" SortExpression="Available" />
<asp:BoundField DataField="Stock" HeaderText="Stock" SortExpression="Stock" />
<asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="UploadImage.aspx?Id={0}" Text="Upload Image" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="ProductsGridView_DS" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:db_1318766_zaraConnectionString %>" DeleteCommand="DELETE FROM [Products] WHERE [Id] = @original_Id AND [Name] = @original_Name AND [Description] = @original_Description AND [Gender] = @original_Gender AND [Type] = @original_Type AND [Price] = @original_Price AND (([Available] = @original_Available) OR ([Available] IS NULL AND @original_Available IS NULL)) AND [Stock] = @original_Stock" InsertCommand="INSERT INTO [Products] ([Name], [Description], [Gender], [Type], [Price], [Available], [Stock]) VALUES (@Name, @Description, @Gender, @Type, @Price, @Available, @Stock)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Products]" UpdateCommand="UPDATE [Products] SET [Name] = @Name, [Description] = @Description, [Gender] = @Gender, [Type] = @Type, [Price] = @Price, [Available] = @Available, [Stock] = @Stock WHERE [Id] = @original_Id AND [Name] = @original_Name AND [Description] = @original_Description AND [Gender] = @original_Gender AND [Type] = @original_Type AND [Price] = @original_Price AND (([Available] = @original_Available) OR ([Available] IS NULL AND @original_Available IS NULL)) AND [Stock] = @original_Stock">
<DeleteParameters>
<asp:Parameter Name="original_Id" Type="Int32" />
<asp:Parameter Name="original_Name" Type="String" />
<asp:Parameter Name="original_Description" Type="String" />
<asp:Parameter Name="original_Gender" Type="String" />
<asp:Parameter Name="original_Type" Type="String" />
<asp:Parameter Name="original_Price" Type="Decimal" />
<asp:Parameter Name="original_Available" Type="Boolean" />
<asp:Parameter Name="original_Stock" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="Gender" Type="String" />
<asp:Parameter Name="Type" Type="String" />
<asp:Parameter Name="Price" Type="Decimal" />
<asp:Parameter Name="Available" Type="Boolean" />
<asp:Parameter Name="Stock" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="Gender" Type="String" />
<asp:Parameter Name="Type" Type="String" />
<asp:Parameter Name="Price" Type="Decimal" />
<asp:Parameter Name="Available" Type="Boolean" />
<asp:Parameter Name="Stock" Type="Int32" />
<asp:Parameter Name="original_Id" Type="Int32" />
<asp:Parameter Name="original_Name" Type="String" />
<asp:Parameter Name="original_Description" Type="String" />
<asp:Parameter Name="original_Gender" Type="String" />
<asp:Parameter Name="original_Type" Type="String" />
<asp:Parameter Name="original_Price" Type="Decimal" />
<asp:Parameter Name="original_Available" Type="Boolean" />
<asp:Parameter Name="original_Stock" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>

最佳答案

尝试简化您的删除语句?

例子:

DELETE FROM [Products] WHERE [Id] = @original_Id

我这样说是因为我看到您删除语句需要:“AND [Price] = @original_Price”。您的价格格式可能会影响您删除声明。

因此当您删除它时(价格格式)。一切似乎又恢复正常了。

关于c# - ASP.NET GridView 删除 'Input string was not in a correct format',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29066963/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com