实际上,逗号在文本框中完美执行。 12345 = 12345 但是当我用我的文本框声明javascrip时,我的提交按钮运行不正常:
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (uploadProductPhoto.PostedFile != null)
{
SaveProductPhoto();
ShoppingCart k = new ShoppingCart()
{
ProductName = txtProductName.Text,
ProductImage = "~/ProductImages/" + uploadProductPhoto.FileName,
ProductPrice = txtProductPrice.Text,
ProductDescription = txtProductDescription.Text,
CategoryID = Convert.ToInt32(ddlCategory.SelectedValue),
TotalProducts = Convert.ToInt32(txtProductQuantity.Text)
};
k.AddNewProduct();
ClearText();
Label2.Text = "Product Added!";
//Response.Redirect("AddNewProduct.aspx?alert=success");
}
else
{
Response.Write("<script>alert('Please upload photo');</script>");
这是我的按钮代码:
ALTER PROCEDURE [dbo].[SP_AddNewProduct]
(
@ProductName varchar(300),
@ProductPrice varchar(500),
@ProductImage varchar(500),
@ProductDescription varchar(1000),
@CategoryID int,
@ProductQuantity int
)
AS
BEGIN
BEGIN TRY
Insert into products
values
(@ProductName,
@ProductDescription,
@ProductPrice,
@ProductImage,
@CategoryID,
@ProductQuantity
)
END TRY
BEGIN CATCH
PRINT ('Error Occured')
END CATCH
END
代码已完成(&#34;产品已添加&#34;正在显示)但是,产品实际上并未添加。它不在数据库或任何地方。对此有什么诡计吗?
这是k.AddNewProduct();
{{1}}
答案 0 :(得分:0)
我使用简化的正则表达式
function Comma(Num) {
var parts = Num.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
}
如果您还需要支持带小数的数字,请使用以下代码
function numberWithCommas(n) {
var parts=n.toString().split(".");
return parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (parts[1] ? "." + parts[1] : "");
}