编程实现>ASP.NET 3.5开发范例精讲精析>探讨FormView控件
FormView没有内置html表格样式,但功能与FormView一样。这意味着,功能我来,外观你来。
FormView控件的精微物质:各种显示模板(编辑,空数据,页头,页脚,纯显示,插入,分页),事件(插入,绑定,编辑等待),可视化绑定。
只是显示<%# Eval("数据库字段") %>,更新<%# Bind("数据库字段") %>
编程实现>ASP.NET 3.5开发范例精讲精析>探讨FormView控件>最浅显的例子
FormView控件超基础例子
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="demo004.aspx.cs" Inherits="study_chapter12_demo004" %>
<!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控件超基础例子</title>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource2" DataTextField="部门" DataValueField="部门">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:chtNorthwind %>"
DataSourceMode="DataReader"
SelectCommand="SELECT DISTINCT [部门] FROM [章立民研究室] ORDER BY [部门]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="员工号码" DataSourceID="SqlDataSource1"
EnableViewState="False">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="员工号码" HeaderText="员工号码" InsertVisible="False"
ReadOnly="True" SortExpression="员工号码" />
<asp:BoundField DataField="姓名" HeaderText="姓名" SortExpression="姓名" />
<asp:BoundField DataField="性别" HeaderText="性别" SortExpression="性别" />
<asp:BoundField DataField="部门" HeaderText="部门" SortExpression="部门" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:chtNorthwind %>"
SelectCommand="SELECT [员工号码], [姓名], [性别], [部门] FROM [章立民研究室] WHERE ([部门] = @部门)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="部门"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="员工号码"
DataSourceID="SqlDataSource3">
<ItemTemplate>
<table border="1">
<tr><td>员工号码:<asp:Label ID="Label1" runat="server" Text='<%#Eval("员工号码") %>'>'></asp:Label></td></tr>
</table>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:chtNorthwind %>"
SelectCommand="SELECT * FROM [章立民研究室] WHERE ([员工号码] = @员工号码)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="员工号码"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
<!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控件超基础例子</title>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource2" DataTextField="部门" DataValueField="部门">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:chtNorthwind %>"
DataSourceMode="DataReader"
SelectCommand="SELECT DISTINCT [部门] FROM [章立民研究室] ORDER BY [部门]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="员工号码" DataSourceID="SqlDataSource1"
EnableViewState="False">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="员工号码" HeaderText="员工号码" InsertVisible="False"
ReadOnly="True" SortExpression="员工号码" />
<asp:BoundField DataField="姓名" HeaderText="姓名" SortExpression="姓名" />
<asp:BoundField DataField="性别" HeaderText="性别" SortExpression="性别" />
<asp:BoundField DataField="部门" HeaderText="部门" SortExpression="部门" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:chtNorthwind %>"
SelectCommand="SELECT [员工号码], [姓名], [性别], [部门] FROM [章立民研究室] WHERE ([部门] = @部门)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="部门"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="员工号码"
DataSourceID="SqlDataSource3">
<ItemTemplate>
<table border="1">
<tr><td>员工号码:<asp:Label ID="Label1" runat="server" Text='<%#Eval("员工号码") %>'>'></asp:Label></td></tr>
</table>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:chtNorthwind %>"
SelectCommand="SELECT * FROM [章立民研究室] WHERE ([员工号码] = @员工号码)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="员工号码"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
合乎自然而生生不息。。。