科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道应用软件用ASP.NET 2.0 FormView控件控制显示

用ASP.NET 2.0 FormView控件控制显示

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

ASP.NET 2.0的FormView控件类似于DetailsView控件,因为它能方便地显示后端数据源的单个记录。本文将讨论这个控件的语法和应用。

作者: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领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章