asp.net %% %#%%=%%@%%$%用法与区别
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>
6.DataBind,獲得的數據,系統會將其默認為String,怎樣轉化為其它的類型?
DataBinder.eval_r(Container.DataItem,"轉換的類型","格式")? 注:格式可以不要 此方法=eval_r("轉換的類型")
轉載于:https://www.cnblogs.com/TBW-Superhero/p/5519040.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的asp.net %% %#%%=%%@%%$%用法与区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用js技术使字体闪烁
- 下一篇: 优秀ASP.NET程序员修炼之路