zoukankan      html  css  js  c++  java
  • webform 对表的增删改查

    增删改查的方法代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class xiugai : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string id = Request["code"].ToString();
            Car data = new CarBf().Select(id);
            Session["car"] = data;
            TextBox1.Text = data.Code;
            TextBox2.Text = data.Name;
            TextBox3.Text = data.Price.ToString();
            }
            
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
    
            //在这里用session接收要修改的数据,不能再这里new一个新对象
            Car data = (Car)Session["car"];
            data.Code = TextBox1.Text;
            data.Name = TextBox2.Text;
            data.Price = Convert.ToDecimal(TextBox3.Text);
    
            new CarBf().Update(data);
            Response.Redirect("Car.aspx");
    
        }
    }


    主界面里的代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Car1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List<Car> list = new CarBf().Select();
    
            string s = " <table width=' 100%'  border='1'><tr class='tr1'><td>编号</td><td>名称</td><td>价格</td><td>操作</td></tr>";
            foreach (Car data in list)
            {
                s+=" <tr class='tr2'><td>"+data.Code+"</td><td><a href='xianshi.aspx?code="+data.Code+"'>"+data.Name+"</a></td><td>"+data.Price+ "</td><td><a href='Delete.aspx?code=" + data.Code + "'>删除</a><a href='Update.aspx?code=" + data.Code + "'>修改</a></td></tr>";
            }
            s+="</table><a href='Insert.aspx'>添加<a/>";
            Literal1.Text=s;
        }
    }


    修改代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class xiugai : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string id = Request["code"].ToString();
            Car data = new CarBf().Select(id);
            Session["car"] = data;
            TextBox1.Text = data.Code;
            TextBox2.Text = data.Name;
            TextBox3.Text = data.Price.ToString();
            }
            
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
    
            //在这里用session接收要修改的数据,不能再这里new一个新对象
            Car data =new Car();
            data.Code = TextBox1.Text;
            TextBox1.Enabled = false;
            data.Name = TextBox2.Text;
            data.Price = Convert.ToDecimal(TextBox3.Text);
    
            new CarBf().Update(data);
            Response.Redirect("Car.aspx");
    
        }
    }
  • 相关阅读:
    Linux系统:Centos7搭建Redis单台和集群环境
    Linux系统:Centos7安装Jdk8、Tomcat8、MySQL5.7环境
    Linux系统:常用Linux系统管理命令总结
    转--->svn的使用
    开发中常见的问题
    1.NSThread
    用NSOperation和NSOperationQueue实现多线程编程
    很实用的时间比对算法
    简单的IOS6和IOS7通过图片名适配
    nginx完美支持tp框架
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4661981.html
Copyright © 2011-2022 走看看