簡體   English   中英

在ListView的ItemTemplate中獲取當前有界對象

[英]Get the current bounded object in a ListView's ItemTemplate

我希望能夠在ListView控件的ItemTemplate中獲取當前綁定對象。

這是我想要做的一個例子:

<asp:ListView ID="UserList" runat="server">
    <LayoutTemplate>
        <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
    </LayoutTemplate>
    <ItemTemplate>
        //How can I get the current bound object in here?
    </ItemTemplate>
</asp:ListView>

您可以通過DataItem訪問它:

<%# DataBinder.Eval(Container.DataItem, "myPropertyName")%>'

如果你想要一個文本框,例如:

<asp:Label ID="MyProp" runat="server" Text='<%#Eval("myPropertyName") %>' />

如果你只想要完整的對象:

<%# (MyType)Container.DataItem %>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM