How to change the method code
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls; Public Partial classxiugai:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) { if(!IsPostBack) { stringid = request["Code"]. ToString (); Car Data=NewCARBF (). Select (ID); session["Car"] =data; TextBox1.Text=data. Code; TextBox2.Text=data. Name; TextBox3.Text=data. Price.tostring (); } } protected voidButton1_Click (Objectsender, EventArgs e) { //in this case, you can use the session to receive the data you want to modify, and no new objectCar data = (CAR) session["Car"]; Data. Code=TextBox1.Text; Data. Name=TextBox2.Text; Data. Price=Convert.todecimal (TextBox3.Text); NewCARBF (). Update (data); Response.Redirect ("car.aspx"); }}
The code in the main interface
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls; Public Partial classcar1:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) {List<Car> list =NewCARBF (). Select (); strings ="<table width= ' 100% ' border= ' 1 ' ><tr class= ' TR1 ' ><td> numbering </td><td> name </td>< Td> Price </td><td> Operation </td></tr>"; foreach(Car datainchlist) {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 +"' > Delete </a><a href= ' update.aspx?code="+ data. Code +"' > Modify </a></td></tr>"; } s+="</table><a href= ' insert.aspx ' > Add <a/>"; Literal1.text=R; }}
Modify Code
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls; Public Partial classxiugai:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) { if(!IsPostBack) { stringid = request["Code"]. ToString (); Car Data=NewCARBF (). Select (ID); session["Car"] =data; TextBox1.Text=data. Code; TextBox2.Text=data. Name; TextBox3.Text=data. Price.tostring (); } } protected voidButton1_Click (Objectsender, EventArgs e) { //in this case, you can use the session to receive the data you want to modify, and no new objectCar data =NewCar (); Data. Code=TextBox1.Text; Textbox1.enabled=false; Data. Name=TextBox2.Text; Data. Price=Convert.todecimal (TextBox3.Text); NewCARBF (). Update (data); Response.Redirect ("car.aspx"); }}
WebForm to change the table and delete