Get the current restricted object in a ListView ItemTemplate

I want to get the current linked object in the ItemTemplate of a ListView control.

Here is 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> 
+7
c # data-binding listview
source share
1 answer

You can access it through the DataItem:

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

If you need a text box, for example:

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

If you only need the full object:

 <%# (MyType)Container.DataItem %> 
+10
source share

All Articles