• 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("转换的类型")

  • 相关阅读:
    算法训练 区间k大数查询
    算法训练 最大最小公倍数
    身份证号码升级
    python包与模块导入
    python函数
    HDU 3595 博弈论,被支配的恐惧
    BZOJ 3195 [Jxoi2012]奇怪的道路
    大暑假集训
    [Poi2010]Monotonicity 2
    BZOJ 4868 HEOI 期末考试
  • 原文地址:https://www.cnblogs.com/TBW-Superhero/p/5519040.html
Copyright © 2020-2023  润新知