資料繫結運算式

來源:互聯網
上載者:User

 

 

資料繫結運算式
ASP.NET 2.0 改進了模板中的資料繫結,將資料繫結文法由完整的 v1.x 文法 DataBinder.Eval(Container.DataItem, fieldname) 簡化為 Eval(fieldname)。與 DataBinder.Eval 一樣,Eval 方法也接受一個可選的 formatString 參數。縮寫的 Eval 文法與 DataBinder.Eval 的不同之處,在於 Eval 根據最近的容器物件(在上面的樣本中為 DataListItem)的 DataItem 屬性自動解析欄位,而 DataBinder.Eval 接受該容器的一個參數。因此,Eval 僅在資料繫結控制項的模板中使用,而不能在“頁”層級使用。當然,ASP.NET 2.0 頁繼續支援 DataBinder.Eval,因此它可用於簡化的 Eval 文法不受支援的場合。

<asp:DataList DataSourceID="ObjectDataSource1" runat="server">
  <ItemTemplate>
    <asp:Image ImageUrl='<%# Eval("FileName", "images/thumbs/{0}") %>' runat="server"/>
    <asp:Label Text='<%# Eval("Caption") %>' runat="server"/>
  </ItemTemplate>
</asp:DataList>

      <asp:DataList ID="DataList1" RepeatColumns="5" Width="600" runat="server" DataSourceID="ObjectDataSource1">
        <ItemTemplate>
          <br />
          <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("PhotoID", "PhotoFormViewPlain.aspx?ID={0}") %>'>
          <asp:Image ID="Image1" Runat="server" ImageUrl='<%# Eval("FileName", "images/thumbs/{0}") %>' /></asp:HyperLink>
          <br />
          <asp:Label ID="CaptionLabel" runat="server" Text='<%# Eval("Caption") %>' />
        </ItemTemplate>
      </asp:DataList><br />

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.