- <% %>
- <%= %>
- <%# %>
- <%# %> 的应用
前台代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>测试网站</title>
</head>
<body>
<div>
<h1 style="text-align:center">测试网站</h1>
<%#stringRead %>
</div>
</body>
</html>
后台代码
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
public string stringRead = "1213";
protected void Page_Load(object sender, EventArgs e)
{
Page.DataBind();
}
}
运行效果:
注意事项:绑定内容必须是外部客可访问的,不能是私有或受保护属性,同时必须使用页面绑定才能看到效果。
2.
<%= %>的用法
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>测试网站</title>
</head>
<body>
<div>
<h1 style="text-align:center">测试网站</h1>
<%=BindString()%>
</div>
</body>
</html>
后台代码:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
public string stringRead = "1213";
protected void Page_Load(object sender, EventArgs e)
{
}
public string BindString()
{
return "<%= %>绑定表达式应用!";
}
}
运行效果:
![]()
3.<% %>的用法
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>测试网站</title>
</head>
<body>
<div>
<h1 style="text-align:center">测试网站</h1>
<%BingList();%>
</div>
</body>
</html>
后台代码:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
public string stringRead = "1213";
protected void Page_Load(object sender, EventArgs e)
{
}
public void BingList()
{
Response.Write("<ul>\n");
for(int i=0;i<10;i++)
{
Response.Write("<li>" + i.ToString() + "行" + "</li>");
}
Response.Write("</ul>\n");
}
}
运行效果:
![]()
- <%# %> 的应用
前台代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>测试网站</title>
</head>
<body>
<div>
<h1 style="text-align:center">测试网站</h1>
<%#stringRead %>
</div>
</body>
</html>
后台代码
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
public string stringRead = "1213";
protected void Page_Load(object sender, EventArgs e)
{
Page.DataBind();
}
}
运行效果:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>测试网站</title>
</head>
<body>
<div>
<h1 style="text-align:center">测试网站</h1>
<%=BindString()%>
</div>
</body>
</html>
后台代码:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
public string stringRead = "1213";
protected void Page_Load(object sender, EventArgs e)
{
}
public string BindString()
{
return "<%= %>绑定表达式应用!";
}
}
运行效果:
3.<% %>的用法
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>测试网站</title>
</head>
<body>
<div>
<h1 style="text-align:center">测试网站</h1>
<%BingList();%>
</div>
</body>
</html>
后台代码:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
public string stringRead = "1213";
protected void Page_Load(object sender, EventArgs e)
{
}
public void BingList()
{
Response.Write("<ul>\n");
for(int i=0;i<10;i++)
{
Response.Write("<li>" + i.ToString() + "行" + "</li>");
}
Response.Write("</ul>\n");
}
}
运行效果: