1、Web应用程序根运算符~
2、程序代码块语法
<% 嵌入代码程序 %>
<%= 嵌入表达式 %>
例子:<%="好吗" %> 和 <% Response.Write("好吗") %>的结果完全相同
3、服务器端批注语法
<%-- --%>
例子(服务器控件不会显示在网页上,程序代码也不会执行)
<%--
<asp:label id="Label1" runat="server" />
<% int i;
for(int i = 0; i < 5;i++)
{ %>
大家好
<br />
<% } %>
--%>
4、服务器端#Include指示符语法
<!-- #Include file | virtual = filename -->
file用来指定要插入网页中的文件的文件名称和路径,可以使用相对路径
virtual = filename 指定文件是网站中虚拟目录的虚拟路径,可以是相对路径
1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5 <html xmlns="http://www.w3.org/1999/xhtml">
6 <head runat="server">
7 <title>无标题页</title>
8 </head>
9 <body>
10
11 <!-- #Include virtual="Header1.inc" -->
12 <form id="form1" runat="server">
13 <div>
14 正文
15 </div>
16 </form>
17
18 <!-- #Include virtual="Footer.inc" -->
19 </body>
20 </html>
1 <?xml version="1.0" encoding="utf-8" ?>
2 <!-- BEGIN HEADER -->
3
4 <table>
5 <tr>
6 <td>页眉</td>
7 </tr>
8 </table>
9
10 <hr />
11
12
13 <!-- END HEADER -->
14
15 <?xml version="1.0" encoding="utf-8" ?>
16 <!-- BEGIN FOOTER -->
17 <hr />
18 <table>
19 <tr>
20 <td>页脚</td>
21 </tr>
22 </table>
23
24 <!-- END FOOTER -->
5、表达式语法(<%$ expressionPrefix: expressionValue %>)
1、获取连接字符串
1 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
2 ConnectionString="<%$ ConnectionStrings:DBConnection %>"
3
4 SelectCommand="SELECT [UserName], [Mark] FROM [QAUserInfo] ORDER BY [Mark]"></asp:SqlDataSource>
5
6 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
7 DataKeyNames="UserName" DataSourceID="SqlDataSource1" AllowPaging="True">
8 <Columns>
9 <asp:CommandField ShowSelectButton="True" />
10 <asp:BoundField DataField="UserName" HeaderText="UserName" ReadOnly="True"
11 SortExpression="UserName" />
12 <asp:BoundField DataField="Mark" HeaderText="Mark" SortExpression="Mark" />
13 </Columns>
14 </asp:GridView>
1 <!-- 程序信息 -->
2 <appSettings>
3 <add key="CopyRight" value="(C) CopyRight 2011"/>
4 <add key="Application Name" value="Chang Weihua"/>
5 <add key="Studio Name" value="Self"/>
6 </appSettings>
7
8 <asp:Literal ID="Literal1" Text="<%$ AppSettings: copyright %>" runat="server"></asp:Literal>
9 <hr />
10 <asp:Literal ID="Literal2" Text="<%$ AppSettings: Application Name %>" runat="server"></asp:Literal>
11 <hr />
12 <asp:Literal ID="Literal3" Text="<%$ AppSettings: Studio Name %>" runat="server"></asp:Literal>
3、取得资源文件配置
<%$ Resources : Class ,ResourceID %>