3C数码商城物品编辑
加载页面:
var id = Request.QueryString["id"];
var tid = Convert.ToInt32(id);
var product = ProductManager.Select(tid);
if (product != null)
{
Session["Product"] = product;
lbID.Text = id;
txtIns.Text = product.Introduction;
txtName.Text = product.ProductName;
txtPrice.Text = product.SellingPrice + "";
txtSale.Text = product.MarketPrice + "";
Checkbox1.Checked = product.IsOnSale == 1;
DropDownList1.SelectedValue = product.CategoryId + "";
}
提交按钮:
var product = Session["Product"] as Product;
product.Introduction = txtIns.Text;
product.ProductName = txtName.Text;
product.SellingPrice = Convert.ToDouble(txtPrice.Text);
product.MarketPrice = Convert.ToDouble(txtSale.Text);
product.IsOnSale = Checkbox1.Checked ? 1 : 0;
product.CategoryId = Convert.ToInt32(DropDownList1.SelectedValue);
var num = ProductManager.Update(product);
if (num > 0)
{
Response.Write("<script>alert('修改成功');location.href='Index.aspx'</script>");
}
*使用 Session保存提取