Displaying Data with ItemTemplate

Displaying Data with ItemTemplate

The ItemTemplate is used to define the layout of each individual item that is bound to the ListView control. The ItemTemplate property is used to specify the template for a single item in the ListView control.

Here’s an example of how to use the ItemTemplate to display data from a LinqDataSource control:

<asp:LinqDataSource ID=”myDataSource” runat=”server”

    ContextTypeName=”MyDataContext” TableName=”MyTable”>

</asp:LinqDataSource>

<asp:ListView ID=”myListView” runat=”server” DataSourceID=”myDataSource”>

    <LayoutTemplate>

        <ul>

            <asp:PlaceHolder ID=”itemPlaceholder” runat=”server” />

        </ul>

    </LayoutTemplate>

    <ItemTemplate>

        <li>

            <%# Eval(“ColumnName1”) %> – <%# Eval(“ColumnName2”) %>

        </li>

    </ItemTemplate>

</asp:ListView>

In this example, the LinqDataSource control is bound to the MyTable table in the MyDataContext data context. The ListView control is then bound to the LinqDataSource control. The LayoutTemplate is used to define the overall layout of the ListView control, and the ItemTemplate is used to define the layout of each individual item.

In the ItemTemplate, we use the Eval method to bind the values of the ColumnName1 and ColumnName2 fields to the <li> element. This will display the values of those fields for each item in the ListView control.

Apply for ASP.NET Certification Now!!

https://www.vskills.in/certification/certified-aspnet-programmer

Back to Tutorial

Custom session handlers in PHP
Editing Records with EditItemTemplate

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?