当我更新 gridview 行时,十进制值会自动四舍五入。假设编辑文本框中的价格值为 1.25,则变为 1 等。sql 表中的数据类型为 numeric(18,2)。请帮我解决问题。
enter code here
protected void RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox MPrice = ((TextBox)GridView3.Rows[e.RowIndex].FindControl("txtPrice"));
cmd.Parameters.Add("@Price", SqlDbType.Decimal).Value = decimal.Parse(MPrice.Text);
cmd.ExecuteNonQuery();
}
aspx:
<EditItemTemplate>
<asp:TextBox ID="txtPrice" runat="server" Text='<%# Bind("Price", "{0:n2}") %>'> </asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtPrice" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtPrice" ErrorMessage="*" MaximumValue="99999" MinimumValue=".01" Type="Double"></asp:RangeValidator>
</EditItemTemplate>