零代码,即没有后端代码, 所有东西均通过设计视图拖放完成,下面就是一个使用设计视图完成的留言簿
数据库表 GuestBook:
ID | int | PK,自增 |
Name | varchar(50) | |
varchar(50) | ||
Message | varchar(50) | |
PostDate | datetime | getdate() |
通过设计器产生的代码 lishewen.aspx:
<
%@ Page
Language
="VB"
AutoEventWireup
="false"
CodeFile
="lishewen.aspx.vb"
Inherits
="Myweb_lishewen"
%
>
<! 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 > Untitled Page </ title >
< script type ="text/javascript" >
function pageLoad() {
}
</ script >
</ head >
< body >
< form id ="form1" runat ="server" >
< div >
< asp:ScriptManager ID ="ScriptManager1" runat ="server" />
< h1 >
Message List </ h1 >
< br />
< asp:UpdatePanel ID ="UpdatePanel1" runat ="server" >
< ContentTemplate >
< asp:GridView ID ="messageList" runat ="server" AllowPaging ="True" AutoGenerateColumns ="False"
DataKeyNames ="ID" DataSourceID ="SqlDataSource1" >
< Columns >
< asp:BoundField DataField ="Name" HeaderText ="Name" SortExpression ="Name" ></ asp:BoundField >
< asp:BoundField DataField ="Email" HeaderText ="Email" SortExpression ="Email" ></ asp:BoundField >
< asp:BoundField DataField ="Message" HeaderText ="Message" SortExpression ="Message" ></ asp:BoundField >
< asp:BoundField DataField ="PostDate" HeaderText ="PostDate" SortExpression ="PostDate" >
</ asp:BoundField >
</ Columns >
</ asp:GridView >
</ ContentTemplate >
</ asp:UpdatePanel >
</ div >
< asp:SqlDataSource ID ="SqlDataSource1" runat ="server" ConnectionString ="<%$ ConnectionStrings:DatabaseConnectionString %>"
DeleteCommand ="DELETE FROM [GuestBook] WHERE [ID] = @ID" InsertCommand ="INSERT INTO [GuestBook] ([Name], [Email], [Message], [PostDate]) VALUES (@Name, @Email, @Message, getdate())"
SelectCommand ="SELECT * FROM [GuestBook]" UpdateCommand ="UPDATE [GuestBook] SET [Name] = @Name, [Email] = @Email, [Message] = @Message, [PostDate] = getdate() WHERE [ID] = @ID" >
< DeleteParameters >
< asp:Parameter Name ="ID" Type ="Int32" />
</ DeleteParameters >
< UpdateParameters >
< asp:Parameter Name ="Name" Type ="String" />
< asp:Parameter Name ="Email" Type ="String" />
< asp:Parameter Name ="Message" Type ="String" />
< asp:Parameter Name ="PostDate" Type ="DateTime" />
< asp:Parameter Name ="ID" Type ="Int32" />
</ UpdateParameters >
< InsertParameters >
< asp:Parameter Name ="Name" Type ="String" />
< asp:Parameter Name ="Email" Type ="String" />
< asp:Parameter Name ="Message" Type ="String" />
< asp:Parameter Name ="PostDate" Type ="DateTime" />
</ InsertParameters >
</ asp:SqlDataSource >
< br />
< h1 >
Insert a Message </ h1 >
< br />
< asp:UpdatePanel ID ="UpdatePanel2" runat ="server" UpdateMode ="Conditional" >
< ContentTemplate >
< asp:DetailsView ID ="addingForm" runat ="server" AutoGenerateRows ="False" DataKeyNames ="ID"
DataSourceID ="SqlDataSource1" Height ="50px" Width ="125px" DefaultMode ="Insert" >
< Fields >
< asp:BoundField DataField ="Name" HeaderText ="Name" SortExpression ="Name" ></ asp:BoundField >
< asp:BoundField DataField ="Email" HeaderText ="Email" SortExpression ="Email" ></ asp:BoundField >
< asp:BoundField DataField ="Message" HeaderText ="Message" SortExpression ="Message" ></ asp:BoundField >
< asp:CommandField ShowInsertButton ="True" ></ asp:CommandField >
</ Fields >
</ asp:DetailsView >
</ ContentTemplate >
</ asp:UpdatePanel >
< asp:UpdateProgress ID ="UpdateProgress1" runat ="server" >
< ProgressTemplate >
< div style ="position: absolute; top: 2px; left: 0px; width: 103%; text-align: right" >
< span style ="background-color: rgb(204,68,68)" > Loading... </ span ></ div >
</ ProgressTemplate >
</ asp:UpdateProgress >
</ 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 > Untitled Page </ title >
< script type ="text/javascript" >
function pageLoad() {
}
</ script >
</ head >
< body >
< form id ="form1" runat ="server" >
< div >
< asp:ScriptManager ID ="ScriptManager1" runat ="server" />
< h1 >
Message List </ h1 >
< br />
< asp:UpdatePanel ID ="UpdatePanel1" runat ="server" >
< ContentTemplate >
< asp:GridView ID ="messageList" runat ="server" AllowPaging ="True" AutoGenerateColumns ="False"
DataKeyNames ="ID" DataSourceID ="SqlDataSource1" >
< Columns >
< asp:BoundField DataField ="Name" HeaderText ="Name" SortExpression ="Name" ></ asp:BoundField >
< asp:BoundField DataField ="Email" HeaderText ="Email" SortExpression ="Email" ></ asp:BoundField >
< asp:BoundField DataField ="Message" HeaderText ="Message" SortExpression ="Message" ></ asp:BoundField >
< asp:BoundField DataField ="PostDate" HeaderText ="PostDate" SortExpression ="PostDate" >
</ asp:BoundField >
</ Columns >
</ asp:GridView >
</ ContentTemplate >
</ asp:UpdatePanel >
</ div >
< asp:SqlDataSource ID ="SqlDataSource1" runat ="server" ConnectionString ="<%$ ConnectionStrings:DatabaseConnectionString %>"
DeleteCommand ="DELETE FROM [GuestBook] WHERE [ID] = @ID" InsertCommand ="INSERT INTO [GuestBook] ([Name], [Email], [Message], [PostDate]) VALUES (@Name, @Email, @Message, getdate())"
SelectCommand ="SELECT * FROM [GuestBook]" UpdateCommand ="UPDATE [GuestBook] SET [Name] = @Name, [Email] = @Email, [Message] = @Message, [PostDate] = getdate() WHERE [ID] = @ID" >
< DeleteParameters >
< asp:Parameter Name ="ID" Type ="Int32" />
</ DeleteParameters >
< UpdateParameters >
< asp:Parameter Name ="Name" Type ="String" />
< asp:Parameter Name ="Email" Type ="String" />
< asp:Parameter Name ="Message" Type ="String" />
< asp:Parameter Name ="PostDate" Type ="DateTime" />
< asp:Parameter Name ="ID" Type ="Int32" />
</ UpdateParameters >
< InsertParameters >
< asp:Parameter Name ="Name" Type ="String" />
< asp:Parameter Name ="Email" Type ="String" />
< asp:Parameter Name ="Message" Type ="String" />
< asp:Parameter Name ="PostDate" Type ="DateTime" />
</ InsertParameters >
</ asp:SqlDataSource >
< br />
< h1 >
Insert a Message </ h1 >
< br />
< asp:UpdatePanel ID ="UpdatePanel2" runat ="server" UpdateMode ="Conditional" >
< ContentTemplate >
< asp:DetailsView ID ="addingForm" runat ="server" AutoGenerateRows ="False" DataKeyNames ="ID"
DataSourceID ="SqlDataSource1" Height ="50px" Width ="125px" DefaultMode ="Insert" >
< Fields >
< asp:BoundField DataField ="Name" HeaderText ="Name" SortExpression ="Name" ></ asp:BoundField >
< asp:BoundField DataField ="Email" HeaderText ="Email" SortExpression ="Email" ></ asp:BoundField >
< asp:BoundField DataField ="Message" HeaderText ="Message" SortExpression ="Message" ></ asp:BoundField >
< asp:CommandField ShowInsertButton ="True" ></ asp:CommandField >
</ Fields >
</ asp:DetailsView >
</ ContentTemplate >
</ asp:UpdatePanel >
< asp:UpdateProgress ID ="UpdateProgress1" runat ="server" >
< ProgressTemplate >
< div style ="position: absolute; top: 2px; left: 0px; width: 103%; text-align: right" >
< span style ="background-color: rgb(204,68,68)" > Loading... </ span ></ div >
</ ProgressTemplate >
</ asp:UpdateProgress >
</ form >
</ body >
</ html >