asp.net ListView Control Learning Series 2-Edit listview (Edit,update,insert,delete)

Source: Internet
Author: User
Tags eval

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>
&LT;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;}
}

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.