Public Partial classedit:system.web.ui.page{PrivateMydbdatacontext _context =NewMydbdatacontext (); //Bound Nation Private voidfillnation () {List<Nation> list =_context.nation.tolist (); Txtnation.datasource=list; Txtnation.datatextfield="Name"; Txtnation.datavaluefield="Code"; Txtnation.databind (); } //in the Modify page get people primary key value load people information Private voidFillloadinfo () {stringCode = request["ID"]; varquery = _context.info.where (p = = P.code = =Code); if(Query. Count () >0) {Info data=query. First (); Txtcode.text=data. Code; txtName.Text=data. Name; Txtsex.selectedvalue=data. Sex.tostring (); Txtnation.selectedvalue=data. Nation; Txtbirthday.text= data. Birthday.Value.ToString ("yyyy mm month DD Day"); } } //loading national and personal information protected voidPage_Load (Objectsender, EventArgs e) { if(!IsPostBack) {fillnation (); Fillloadinfo (); } } //returns the page that displays the information protected voidButton1_Click (Objectsender, EventArgs e) {Response.Redirect ("modify information. aspx"); } //Modify update information protected voidBtnok_click (Objectsender, EventArgs e) { //identify the object you want to modify stringCode =Txtcode.text; varquery = _context.info.where (P=>p.code = =code); if(Query. Count () >0) {Info data=query. First (); //ModifyData. Name =txtName.Text; Data. Sex=Convert.toboolean (Txtsex.text); Data. Nation=Txtnation.text; Data. Birthday=Convert.todatetime (Txtbirthday.text); //Submit_context.submitchanges (); } }}
Repeater binding Data:
Private New Mydbdatacontext (); protected void Page_Load (object sender, EventArgs e) { if (! IsPostBack) { list<Info> list = _context.info.tolist (); = list; Repeater1.databind (); } }
To modify an information hyperlink:
1.a Tags:
<a href="edit.aspx?id=<% #Eval ("Code")%>"> Modify </a>
2.HyperLink button
public string Showhref () { return " edit.aspx?id= + Eval (" code ); } <asp:hyperlink Id= hyperlink1 runat=" Server navigateurl=" <% #ShowHref ()%> > Modify </asp:HyperLink> </t D>
Webform---Modify personnel information