First, edit, cancel, update operation
First drag a ListView control to the page, and then adjust it as follows, in order to take advantage of the built-in features of the buttons in the ListView control CommandName must be the same as our name here.
Front-end Code
<asp:listview id= "ListView1" runat= "Server" onitemediting= "listview1_itemediting"
onitemcanceling= "listview1_itemcanceling" onitemupdating= "listview1_itemupdating" >
<ItemTemplate>
<tr>
<td>
<% #Eval ("ID")%>
</td>
<td>
<% #Eval ("name")%>
</td>
<td>
<asp:button id= "Editbutton" runat= "Server" text= "edit" commandname= "edit"/>
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td>
<asp:label id= "idlable" runat= "server" text= ' <% #Eval ("ID")%> '/>
</td>
<td>
<asp:textbox id= "nameTextBox" runat= "server" text= ' <% #Bind ("Name")%> '/>
</td>
<td>
<asp:button id= "UpdateButton" runat= "Server" commandname= "Update" text= "Update"/>
<asp:button id= "CancelButton" runat= "Server" commandname= "Cancel" text= "Cancel"/>
</td>
</tr>
</EditItemTemplate>
<LayoutTemplate>
<table>
<TR runat= "Server" id= "Itemplaceholder" >
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
Here we add the DataAccess class to the App_Code folder to simulate the availability of the data, as follows:
Analog Data Supply Code
public class DataAccess
{
Public list<employee> List;
Public DataAccess ()
{
List = new list<employee> ();
Employee E1 = New Employee {id=1, Name = "lfm1", age = 30};
Employee E2 = New Employee {id=2, Name = "lfm2", age = 30};
Employee E3 = new Employee {id=3, Name = "lfm3", age = 30};
Employee E4 = New Employee {id=4, Name = "LFM4", age = 30};
Employee E5 = new Employee {id=5, Name = "LFM5", age = 30};
Employee E6 = New Employee {id=6, Name = "LFM6", age = 30};
List.add (E1);
List.add (E2);
List.add (E3);
List.add (E4);
List.add (E5);
List.add (E6);
}
}
public class Employee
{
public int ID {get; set;}
public string Name {get; set;}
public int Age {get; set;}
public int Sex {get; set;}
}