gpt4 book ai didi

c# - 不能为负,避免在文本框上输入字母

转载 作者:行者123 更新时间:2023-11-30 20:36:37 25 4
gpt4 key购买 nike

<分区>

这是 txtProductQuantity_TextChange 的全部代码:

protected void txtProductQuantity_TextChanged(object sender, EventArgs e)
{
TextBox txtQuantity = (sender as TextBox);

//int tempForTryParse = 0;
//if (!int.TryParse(txtQuantity.Text, out tempForTryParse))
//{
// txtQuantity.Text = txtQuantity.Text.Substring(0, txtQuantity.Text.Length - 1);
//}

DataListItem currentItem = (sender as TextBox).NamingContainer as DataListItem; // getting current item on where user wants to add or remove
HiddenField ProductID = currentItem.FindControl("hfProductID") as HiddenField;
Label lblAvailableStock = currentItem.FindControl("lblAvailableStock") as Label;

int tempInt = 0;
if (txtQuantity.Text == string.Empty || txtQuantity.Text == "0" || txtQuantity.Text == "1" || double.Parse(txtQuantity.Text) < 0 || !int.TryParse(txtQuantity.Text, out tempInt))
{
txtQuantity.Text = "1"; //default value is 1, no action
}
else
{
if (Session["MyCart"] != null) // not null means user has added a product in the shopping cart
{
if (Convert.ToInt32(txtQuantity.Text) <= Convert.ToInt32(lblAvailableStock.Text)) // check if quantity is greater than available stock
{
DataTable dt = (DataTable)Session["MyCart"]; // if quantity is less than the available stock, go inside the code

DataRow[] rows = dt.Select("ProductID = '" + ProductID.Value + "'"); // select specific row depending on the product id

int index = dt.Rows.IndexOf(rows[0]);

dt.Rows[index]["ProductQuantity"] = txtQuantity.Text; // putting the value in the txtQuantityTextbox. changing the product quantity in the data table

Session["MyCart"] = dt; // add updated value to datatable
}
else // error if quntity is greater than available stock
{
lblAvailableStockAlert.Text = " Alert: product buyout should not be more than the available stock!";
txtQuantity.Text = "1"; // automatically change the quantity back to 1.
}

}
}
UpdateTotalBill();
}

我想要发生的是避免用户输入字母。如果他们这样做,或者类似的东西将默认为“1”。

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