Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the current bounded object in a ListView's ItemTemplate

I want to be able to get the current bound object in the ItemTemplate of a ListView control.

Here's an example of what I want to do:

<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>
like image 974
Andreas Grech Avatar asked Mar 14 '10 12:03

Andreas Grech


1 Answers

You can access it via the DataItem:

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

If you wanted a textbox for example:

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

If you just want the full object:

<%# (MyType)Container.DataItem %>
like image 87
Nick Craver Avatar answered Nov 13 '22 10:11

Nick Craver