Webfrom--Hyperlink transfer value

Source: Internet
Author: User

(a) Connecting the car table add a database method (MyDB)

namespaceConnecting to a database _ look up table { Public classMyDB {PrivateMydbdatacontext context =NewMydbdatacontext (); Public list<car> Select ()//The table is all queried {return context.                Car.tolist (); }         PublicCar Select1 (stringCode//Query        {            varQuery = context. Car.where (p = P.code = =code); if(Query. Count () >0)            {                returnquery.            First (); }            return NULL; }        Public bool Update (Car C)//modify {var query = context.            Car.where (p = p.code== c.code); if (query. Count () >0) {Car a = query.                First ();                A.name = C.name;                A.brand = C.brand; Context.                SubmitChanges ();            return true;            } else {return false; }                }         Public voidDelete (stringCode//Delete        {            varQuery = context. Car.where (p = P.code = =code); if(Query. Count () >0) {Car stu=query.                First (); Context.                Car.deleteonsubmit (Stu); Context.            SubmitChanges (); }        }        Public bool All (Car a)//increment {try {context.                Car.insertonsubmit (a); Context.                SubmitChanges ();            return true; } catch {return false; }                              }         }}

(ii) Add a web window (che.aspx)

usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;namespaceConnecting to a database _ look up table { Public Partial classChe:System.Web.UI.Page {  protected void Page_Load (object sender, EventArgs e)//show everything in the table { list<car> list = new MyDB ().            Select (); string s = "<table width= ' 100% ' border=1 ><tr><td> numbering </td><td> name </td><td> type            </td><td> Delete </td><td> add </td></tr> "; foreach (Car date in list) {s + = "<tr><td>" + date. Brand + "</td><td><a href= ' update.aspx?code=" + date. Code + ">" + date. Name + "</a></td><td>" + date. Brand + "</td><td><a href= ' delete.aspx?code=" + date.            Code + "' > Delete </a></td><td><a href= ' all.aspx ' > Add </a></td></tr>";            } s + = "</table>"; Literal1.text =  s; }    }
}

(iii) Add an additional Web Form (all.aspx)

< View >

<div> <asp:label id="Label1"runat="Server"text="numbering"></asp:Label> <asp:textbox id="TextBox1"runat="Server"></asp:TextBox> <br/> <asp:label id="Label2"runat="Server"text="name"></asp:Label> <asp:textbox id="TextBox2"runat="Server"></asp:TextBox> <br/> <asp:label id="Label3"runat="Server"text="type"></asp:Label> <asp:textbox id="TextBox3"runat="Server"></asp:TextBox> <br/> <asp:button id="Button1"runat="Server"onclick="Button1_Click"text="Confirm Increase"/> <asp:button id="Button2"runat="Server"onclick="button2_click"text="Back to Home"/> </div>

< code >

namespaceConnecting to a database _ look up table { Public Partial classAll:System.Web.UI.Page {protected voidPage_Load (Objectsender, EventArgs e) {                   }        protected voidButton1_Click (Objectsender, EventArgs e)//Add {Car a=NewCar (); A.code=TextBox1.Text; A.name=TextBox2.Text; NewMyDB ().            All (a); Response.Redirect ("che.aspx"); }        protected voidButton2_Click (Objectsender, EventArgs e)//return {Response.Redirect ("che.aspx");//go to the page's interface        }    }}

(iv) deletion (delete.aspx)

Add a Delete webfrom window

namespace Connection Database _ Look up table    {publicpartialclass  delete:System.Web.UI.Page    {         protectedvoid Page_Load (object  sender, EventArgs e)        {             new MyDB (). Delete (request["code"). ToString ());            Response.Redirect ("che.aspx");     }}}

(v) Amendment (update.aspx)

< View >

<div> <asp:label id="Label1"runat="Server"text="numbering"></asp:Label> <asp:textbox id="TextBox1"runat="Server"></asp:TextBox> <br/> <asp:label id="Label2"runat="Server"text="name"></asp:Label> <asp:textbox id="TextBox2"runat="Server"></asp:TextBox> <br/> <asp:label id="Label3"runat="Server"text="type"></asp:Label> <asp:textbox id="TextBox3"runat="Server"></asp:TextBox> <br/> <asp:button id="Button1"runat="Server"onclick="Button1_Click"text="Confirm Changes"/> <asp:button id="Button2"runat="Server"onclick="button2_click"text="Back to Home"/> </div>

< code >

namespaceConnecting to a database _ look up table { Public Partial classUpdate:System.Web.UI.Page {protected voidPage_Load (Objectsender, EventArgs e) {            if(!IsPostBack) {                strings = request["Code"].                       ToString (); Car a=NewMyDB ().            Select1 (s); session["Car"] =A; TextBox1.Text=A.code; TextBox2.Text=A.name; TextBox3.Text=A.brand; }                   }        protected voidButton1_Click (Objectsender, EventArgs e)//modify {Car C= (Car) session["Car"]; C.name=TextBox2.Text; C.brand=TextBox3.Text; BOOLisok=NewMyDB ().             Update (c); if(isOK) {Response.Write ("<script> alert (' modified successfully ') </script>"); Response.Redirect ("che.aspx");//go to the page's interface             }             Else{Response.Write ("<script> alert (' Modify failed ') </script>"); }        }        protected voidButton2_Click (Objectsender, EventArgs e)//return home {Response.Redirect ("che.aspx");//go to the page's interface        }    }}

Webfrom--Hyperlink transfer value

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.