標籤:bsp 控制項 ted net text 訪問 system 後台 orm
1.<% %>用來綁定後台代碼
< %for(int i=0;i<10;i++){Reaponse.Write(i.ToString());}%>2、<%# %> 是在繫結控制項DataBind()方法執行時被執行,用於資料繫結
<asp:Label ID="lblId" runat="server" Text=‘<%#Eval("title") %>‘ Visible="false"></asp:Label>
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>
6、<%: %>
這種方式是ASP.NET4.0中新加入的綁定方式,常用於MVC中,但普通webform中也可使用。功能其實就是對綁定的值進行一下編碼,因此,一下兩者是等同的:
<%= Server.HtmlEncode("<b>test</b>") %><%: "<b>test</b>" %>;
ASP.NET <% %>的各種形式用法