当我更新gridview行时,十进制值会自动舍入。假设编辑文本框中的价格值是1.25,那么它变为1等.sql表中的数据类型是数字(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>