asp.net <%%> <%#%><%=%><%@%><%$%>用法区别

来源:互联网 发布:mac无法使用flash 编辑:程序博客网 时间:2024/06/05 07:28

1.<% %>用来绑定后台代码

如:

< %

for(int i=0;i<100;i++)

{

Reaponse.Write(i.ToString());

}

%>

2.<%# %> 是在绑定控件DataBind()方法执行时被执行,用于数据绑定

如: < %# Container.DataItem("title") %>

3.<%= %>用来绑定后台的变量或方法且有返回值 的,但此时的变量名或方法的访问修饰符为protected或public

如:<%=name%> <%=getstr()%>

4.<%@ %>用来导入后台命名空间

如:<%@ import namespace="system.data">

5.<%$ %>用来绑定web.config里的字符串(键值对)

如:<asp:TextBox runat="server" ID="cc" Text="<%$ ConnectionStrings:pubs%>"></asp:TextBox>

web.config

<configuration> 
<system.web> 
<compilation debug="true" targetFramework="4.0" /> 
</system.web> 
<connectionStrings> 
<add name="pubs" connectionString="Server=.;database=pubs;uid=sa;pwd=" providerName="System.Data.SqlClient"/> 
</connectionStrings> 

</configuration>

注:内容写的有点乱,只是学习笔记而已

0 0
原创粉丝点击