<%= %> | <% %> | <%# %> 常用法
一.<%= %> :
获取代码中的变量或属性的值,变量或属性的访问权限要为Protected|public eg:
*.cs文件
Public Class MyClass
{
private string _strValue="MyTest";
protected string strValue
{
get
{
return _strValue;
}
}
}
*.aspx文件
<%=strValue%>
另外用法:
<%= HttpContext.Current.User.Identity.Name %>
二.<% %>
在页面中运行服务器端代码或调用服务器端函数 eg:
*.cs
public void GetString()
{
Response.Write("My Example");
}
*.aspx文件
<% GetString(); %>
三.<%# %>
用于数据绑定 eg:
1.<%# (Container.ItemIndex+1)%2==0 ? "<hr style='color:blue;' />" : String.Empty %>
2.<%# Eval("DataField") %>
3.<%# Container.ClientID+" "+HttpContext.Current.User.Identity.Name %>