主页面编辑超链接
<a href="Edit.aspx?id=<%#Eval("Id") %>">编辑</a>
二级页面
var p = Request.QueryString["Id"];
if (string.IsNullOrEmpty(p))
{
Response.Redirect("index.aspx");
}
if (!IsPostBack)
{
DropDownList1.DataSource = ProductCategoryManage.Select();
DropDownList1.DataValueField = "Id";
DropDownList1.DataTextField = "Name";
DropDownList1.DataBind();
var id = Convert.ToInt32(p);
var pro = ProductManage.Select(id);
if (pro!=null)
{
Label1.Text = pro.Id+"";
txtjian.Text = pro.Introduction;
txtname.Text = pro.ProductName;
txtshi.Text = pro.MarketPrice + "";
txtshou.Text = pro.SellingPrice + "";
DropDownList1.SelectedValue = pro.CategoryId + "";
CheckBox1.Checked = pro.IsOnSale == 1;
}
}
点击修改按钮执行
var id = Convert.ToInt32(Label1.Text);
Product pro = ProductManage.Select(id);
pro.ProductName = txtname.Text;
pro.Introduction = txtjian.Text;
pro.MarketPrice = Convert.ToDouble(txtshi.Text);
pro.SellingPrice = Convert.ToDouble(txtshou.Text);
pro.CategoryId = Convert.ToInt32(DropDownList1.SelectedValue);
if (CheckBox1.Checked)
{
pro.IsOnSale = 1;
}
else
{
pro.IsOnSale = 0;
}
if (ProductManage.Update(pro)>0)
{
Response.Write("<script>alert('修改成功');location.href='Index.aspx'</script>");
}