How do I implement edit, update, and delete functions like the GridView control in a Repeater control? Here is a good example, interested friends can refer to, I hope to help you.
The code is as follows: protected void Page_Load (object sender, EventArgs e) { if (! Page.IsPostBack) { Bindgrid (); } } private void Bindgrid () { string strSQL = "SE Lect * FROM [User] "; oledbconnection objconnection = new OleDbConnection (Getstrconnection ()); Objconnection.open (); OleDbCommand objcommand = new OleDbCommand (strSQL, objconnection); OleDbDataReader Reader = Objcommand.executereader (commandbehavior.closeconnection); Rptuser.datasource = reader; Rptuser.databind (); } protected void Rptuser_itemdatabound (object sender, RepeaterItemEventArgs e) { if (E.item.itemtype = ListItemType.Item | | e.item.itemtype = = listitemtype.alternatingitem) { System . Data.Common.DbDataRecord record = (System.Data.Common.DbDataRecord) e.item.dataitem; int userId = Int. Parse (record["UserId"). ToString ()); if (userId!= ID) { ((panel) E.item.findcontrol ("Plitem")). Visible = true; (panel) E.item.findcontrol ("Pledit"). Visible = false; } else { (panel) E.item.findcontrol ("Plitem")). Visible = false; (panel) E.item.findcontrol ("Pledit"). Visible = true; } } } protected void Rptuser_itemcommand (object source, RepeaterCommandEventArgs e) { if (e.commandname = = "Edit") { id = Int. Parse (E.commandargument.tostring ()); } else if (E.commandname = "Cancel") { id = -1; }&nbs P else if (e.commandname = "Update") { String name = ((TextBox) This.rptuser.items[e.item.itemindex]. FindControl ("Txtname")). Text.trim (); String email = ((TextBox) This.rptuser.items[e.item.itemindex]. FindControl ("Txtemail")). Text.trim (); string qq = ((TextBox) This.rptuser.items[e.item.itemindex]. FindControl ("Txtqq")). Text.trim (); string strSQL = "UPDATE [User] SET name= @Name, email= @Email, qq= @QQ WHERE userid= @UserId"; OleDbConnection objconnection = New OleDbConnection (Getstrconnection ()); OleDbCommand objcommand = new OleDbCommand (strSQL, objConnection); OBJCOMMAND.PARAMETERS.ADD ("@Name", Oledbtype.varwchar); objcommand.parameters["@Name"]. Value = name; objCommand.Parameters.Add ("@Email", Oledbtype.varwchar); objcommand.parameters["@Email"]. Value = email; objCommand.Parameters.Add ("@QQ", Oledbtype.varwchar); objcommand.parameters["@QQ"]. Value = qq; objCommand.Parameters.Add ("@UserId", OleDbType.Integer); objcommand.parameters["@UserId"]. Value = Int. Parse (E.commandargument.tostring ()); Objconnection.open (); objcommand.executenonquery (); Objconnection.close (); } else if (e.commandname = = "Delete") { string strSQL = "Delete * FROM [ R] WHERE userid= @UserId "; OleDbConnection objconnection = new OleDbConnection (Getstrconnection ()); OleDbCommand objcommand = new OleDbCommand (strSQL, objconnection); objcommand.parameters.ADD ("@UserId", OleDbType.Integer); objcommand.parameters["@UserId"]. Value = Int. Parse (E.commandargument.tostring ()); Objconnection.open (); objcommand.executenonquery (); Objconnection.close (); } Bindgrid (); } private String getstrconnection () { return " Provider=Microsoft.Jet.OLEDB.4.0;Data source= "+ Server.MapPath (" ~/database/test.mdb "); } < </code>form id= "Form1" runat= "Server" > <</code>asp:repeater id= "Rptuser" runat= "Server" Onitemcommand= "Rptuser_itemcommand" onitemdatabound= "Rptuser_itemdatabound" > <</CODE> headertemplate> <</code>table width= "960" align= "Center" cellpadding= "3" cellspacing= "1" style= " Background-color: #ccc; " > <</code>thead style= "Background-color: #eee;" > <</CODE>tr> <</code>th width= "10%" > user id </</code>th > <</CODE>TH>&NBSp User name </</CODE>th> <</code>th width= "22%" > Mail </</code>th > <</code>th width= "20%" > qq </</CODE>th> <</code>th Width= "15%" > registration time </</CODE>th> <</code>th width= "12%" > operation </</CODE>th> </</CODE>tr> </</CODE>thead> <</CODE> Tbody style= "Background-color: #fff;" > </</CODE>HeaderTemplate> <</CODE>ItemTemplate> <</CODE> Asp:panel id= "Plitem" runat= "Server" > <</code>tr style= "Text-align:center;" > <</CODE>td>