代码3:ASP.NET的DataList实现数据操作
时间:2005-05-12 来源:bandt
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head><title>DataListEdit.aspx</title></head>
<body>
<form Runat="Server">
<asp:DataList
ID="dlstAuthors"
DataKeyField="au_id"
OnEditCommand="dlstAuthors_EditCommand"
OnCancelCommand="dlstAuthors_CancelCommand"
OnDeleteCommand="dlstAuthors_DeleteCommand"
OnUpdateCommand="dlstAuthors_UpdateCommand"
RepeatColumns="4"
GridLines="Both"
CellPadding="10"
EditItemStyle-BackColor="lightgrey"
Runat="Server">
<ItemTemplate>
<%# Container.DataItem( "au_lname" )%>
- <%# Container.DataItem( "phone" )%>
<br>
<asp:LinkButton
Text="Edit!"
CommandName="edit"
Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<b>Last Name:</b>
<br>
<asp:TextBox
ID="txtLastName"
Text='<%# Container.DataItem( "au_lname" )%>'
Runat="Server" />
<p>
<b>Phone:</b>
<br>
<asp:TextBox
ID="txtPhone"
Text='<%# Container.DataItem( "phone" )%>'
Runat="Server" />
<p>
<asp:LinkButton
Text="Update!"
CommandName="update"
Runat="Server" />
<asp:LinkButton
Text="Delete!"
CommandName="delete"
Runat="Server" />
<asp:LinkButton
Text="Cancel!"
CommandName="cancel"
Runat="Server" />
</EditItemTemplate>
</asp:DataList>
</form>
</body>
</html>