扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:builder.com.cn 2007年3月27日
关键字:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FormView Example</title>
</head><body>
<form id="frmFormViewExample" runat="server">
<asp:SqlDataSource
ID="fvExample"
ConnectionString="Server=localhost;Database=Northwind;Trusted_Connection=true"
SelectCommand="SELECT EmployeeID, LastName, FirstName, HomePhone, HireDate FROM Employees"
Runat="Server"
UpdateCommand="UPDATE Employees SET LastName=@LastName, FirstName=@FirstName, HomePhone=@HomePhone, HireDate=@HireDate WHERE EmployeeID=@EmployeeID"
DeleteCommand="DELETE FROM Employees WHERE EmployeeID=@EmployeeID"
InsertCommand="INSERT INTO Employees (LastName, FirstName, HomePhone, HireDate) VALUES (@LastName, @FirstName, @HomePhone, @HireDate)" />
<div>
<asp:FormView ID="EmpDetails" runat="server"
DataKeyNames="Employeeid"
DataSourceId="fvExample" AllowPaging="true">
<ItemTemplate>
<table style="font-family: Sans Serif; font-size: medium;">
<tr><td colspan="2" style="background: gray; font-weight: bold;">
<%# Eval("LastName") + ", " + Eval("FirstName") %></td></tr>
<tr><td>ID</td>
<td><%# Eval("EmployeeID") %></td></tr>
<tr><td>Phone</td>
<td><%# Eval("HomePhone") %><br></td></tr>
<tr><td>Hired</td>
<td><%# Eval("HireDate", "{0:d}") %><br></td></tr>
<tr><td colspan="2">
<asp:Button ID="btnEdit" CommandName="Edit" Text="Edit" runat="server"/>
<asp:Button ID="btnDelete" CommandName="Delete" Text="Delete" runat="server"/>
<asp:Button ID="btnAdd" CommandName="New" Text="New" runat="server"/></td></tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table>
<tr><td>ID</td>
<td><%# Eval("EmployeeID") %><br></td></tr>
<tr><td>Last Name</td>
<td><asp:TextBoxRunat="server" ID="TextBox2" Text='<%# Bind("LastName") %>' /></td>
</tr>
<tr><td>First Name</td>
<td><asp:TextBoxRunat="server" ID="FirstName" Text='<%# Bind("FirstName") %>' /></td>
</tr>
<tr><td>Phone</td>
<td><asp:TextBoxRunat="server" ID="txtPhone" Text='<%# Bind("HomePhone") %>' /></td>
</tr>
<tr><td>Hire Date</td>
<td><asp:TextBoxRunat="server" ID="txtHireDate" Text='<%# Bind("HireDate") %>' /></td></tr>
<tr><td colspan="2">
<asp:Button ID="btnUpdate" CommandName="Update" Text="Update Employee" runat="server"/>
<asp:Button ID="btnCancel" CommandName="Cancel" Text="Cancel" runat="server"/></td></tr></table>
</EditItemTemplate>
<InsertItemTemplate>
<table>
<tr><td><b>Last Name</b></td>
<td><asp:TextBoxRunat="server" ID="TextBox1" Text='<%# Bind("HomePhone") %>' /></td></tr>
<tr><td><b>First Name</b></td>
<td><asp:TextBoxRunat="server" ID="FirstName" Text='<%# Bind("FirstName") %>' /></td></tr>
<tr><td><b>Home Phone</b></td>
<td><asp:TextBoxRunat="server" ID="txtHomePhone2" Text='<%# Bind("HomePhone") %>' /></td></tr>
<tr><td><b>Hired</b></td>
<td><asp:TextBoxRunat="server" ID="txtHireDate2" Text='<%# Bind("HireDate") %>' /></td></tr>
<tr><td colspan="2">
<asp:Button ID="btnInsert" CommandName="Insert" Text="Save" runat="server"/>
<asp:Button ID="btnCancel2" CommandName="Cancel" Text="Cancel" runat="server"/></td></tr>
</table>
</InsertItemTemplate>
</asp:FormView>
</div></form></body></html>
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者