3C数码商城讲解(ajax删除,页面之间传值)

ajax删除

在UI层中添加一个一般处理程序,并在所添加的一般处理程序中去实现我们的删除代码(具体方法参考下图)

  /// <summary>
    /// Delete 的摘要说明
    /// </summary>
    public class Delete : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            var id = context.Request.Form["id"];
            var tid = Convert.ToInt32(id);
            var num = ProductManager.Delete(tid);
            context.Response.Write(num);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

注意:在添加好一般处理程序后 不要忘了引用BLL层,因为我们要通过BLL层调用删除方法。

然后添加超链接删除按钮

<a href="#" class="delete" data-id='<%# Eval("Id") %>'>删除</a>

添加jQuery脚本,给删除按钮添加事件,处理data 实现无刷新删除数据

<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $(".delete").click(function () {
                if (confirm("确定删除?")) {
                    var $this = $(this);
                    var id = $this.attr("data-id");
                    $.post("/delete.ashx", { id: id }, function (data) {
                        if (data > 0) {
                            $this.closest("tr").remove();
                        }
                    });
                }
            });
        });
    </script>

页面之间传值

编辑页面后台代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;

namespace UI
{
    public partial class Edit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.DataSource = ProductCategoryManager.Select();
                DropDownList1.DataBind();

                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 + "";
                }
            }
        }

        protected void Unnamed1_Click(object sender, EventArgs e)
        {
            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>");
            }
        }
    }
}
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、下4载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、下4载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、 4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值