The ListView control however allows the display of bound data in an HTML template as well as other features such as: sorting, data editing, data insertions, and data deletions.
The following code is the basic structure for the ListView. The placeholder is where each item template will be placed (which is handy when you want a div or other HTML element to wrap around the data items). You can then add the DataPager, which allows for the ListView paging. You will also need the page properties changing event to ensure the paging works seamlessly.
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="10"> <Fields> <asp:NumericPagerField ButtonType="Link" /> </Fields> </asp:DataPager>
protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e) { //set current page startindex, max rows and rebind to false lvDataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false); // bind data to list view BindData(); }
<asp:ListView ID="ListView1" runat="server" OnPagePropertiesChanging="ListView1_PagePropertiesChanging"> <LayoutTemplate> <ul> <asp:PlaceHolder ID="itemPlaceholder" runat="server" /> </ul> </LayoutTemplate> <ItemTemplate> <li> <%# Eval("DataField") %> </li> </ItemTemplate> <EmptyDataTemplate> No data to display </EmptyDataTemplate> </asp:ListView>
No comments:
Post a Comment