ASP.NET 2.0轻松实现数据库应用开发(4)
完成上面的所以步骤后,我们在主页面上的右键菜单上选择"查看代码",可以看到如下的代码:
<%@ Page Language="C#" %>
<html>
<head id="Head1" runat="server">
<title>GridView Bound Fields</title>
</head>
<body>
<form id="form1" runat="server">
<ASP:GridView ID="GridView1" DataSourceID="SqlDataSource1"AutoGenerateColumns="False" runat="server">
<Columns>
<asp:BoundField HeaderText="ID" DataField="au_id" ReadOnly="true" />
<asp:BoundField HeaderText="Last Name" DataField="au_lname" />
<asp:BoundField HeaderText="First Name" DataField="au_fname" />
<asp:BoundField HeaderText="Phone" DataField="phone" />
<asp:BoundField HeaderText="Address" DataField="address" />
<asp:BoundField HeaderText="City" DataField="city" />
<asp:BoundField HeaderText="State" DataField="state" />
<asp:BoundField HeaderText="Zip Code" DataField="zip" />
<asp:CheckBoxField HeaderText="Contract" DataField="contract" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT [au_id], [au_lname], [au_fname], [phone],[address],[city], [state], [zip], [contract] FROM [authors]" ConnectionString="<%$ ConnectionStrings:Pubs %>" />
</form>
</body>
</html>
Web.Config中的代码如下:
<?XML version="1.0"?>
<configuration XMLns="http://schemas.microsoft.com/.netConfiguration/v2.0">
<appSettings/>
<connectionStrings>
<add name="Pubs" connectionString="Data Source=hoowoo;Initial Catalog=pubs;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="false"/>
<authentication mode="Windows"/>
</system.web>
</configuration>
现在来重点分析这些代码的意义:
"<asp:GridView ID="GridView1" DataSourceID="SqlDataSource1"
AutoGenerateColumns="False" runat="server">"
数据绑定控件通过其 DataSourceID 属性连接到数据源控件,从而我们可以进行排序、分页、筛选、更新、删除和插入等一系列的操作。
"<Columns>
<asp:BoundField HeaderText="ID" DataField="au_id" ReadOnly="true" />
<asp:BoundField HeaderText="Last Name" DataField="au_lname" />
<asp:BoundField HeaderText="First Name" DataField="au_fname" />
<asp:BoundField HeaderText="Phone" DataField="phone" />
<asp:BoundField HeaderText="Address" DataField="address" />
<asp:BoundField HeaderText="City" DataField="city" />
<asp:BoundField HeaderText="State" DataField="state" />
<asp:BoundField HeaderText="Zip Code" DataField="zip" />
<asp:CheckBoxField HeaderText="Contract" DataField="contract" />
</Columns>"
"BoundField"和"CheckBoxField"均为要绑定的控件类型,"HeaderText"是将要显示在表格上字段的名称,而"DataField"则是我们要进行绑定的数据字段。
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
SelectCommand="SELECT [au_id], [au_lname], [au_fname],
[phone],[address],[city], [state], [zip], [contract] FROM [authors]"
ConnectionString="<%
相关新闻>>
- 发表评论
-
- 最新评论 更多>>