Asp.Net WebForm 分页

一、 前言

Asp.Net WebForm 内置的DataPager让人十分蛋疼

本文使用的分页控件是第三方分页控件 AspNetPager,下载地址:

链接: http://pan.baidu.com/s/1eQJ2HR8 密码: aost

 

相关属性及其效果图:

 【Asp.Net WebFrom】分页

二、使用第三方分页控件 AspNetPager

第一步:显示未分页时的数据

  

  前端代码:

    注意:将ListView控件的EnableViewState="False"。说明即使是EnableViewState="False",不影响分页的实现。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListView分页AspNetPager第三方控件.aspx.cs" Inherits="Focus.Asp.WebForm.Czbk.Focus.ListView.ListView分页AspNetPager第三方控件" %>


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListView ID="ListView1" runat="server" EnableViewState="False">
                <%--asp.net 3.5的LayoutTemplate是必须的,asp.net 4.0的LayoutTemplate不是必须的--%>
                <LayoutTemplate>
                    <div style="border:solid seagreen;">
                        <table>
                            <thead>
                                <tr>
                                    <th>Id</th>
                                    <th>种类</th>
                                </tr>
                            </thead>
                            <tbody>
                             <%--显示写LayoutTemplate时必须有一个占位符(可以是任意类型),
                                 但是id必须是itemPlaceholder,项占位符控件还必须指定 runat="server"--%>
                                 <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
                            </tbody>
                        </table>
                    </div>
                </LayoutTemplate>
                <ItemTemplate>
                    <div>
                        <tr>
                            <td><asp:Label runat="server"><%#Eval("Id") %></asp:Label></td>
                            <td><asp:Label runat="server"><%#Eval("Kind") %></asp:Label></td>
                        </tr>
                    </div>
                </ItemTemplate>
                <AlternatingItemTemplate>
                    <div >
                        <tr>
                            <td><asp:Label runat="server"><%#Eval("Id") %></asp:Label></td>
                            <td><asp:Label runat="server"><%#Eval("Kind") %></asp:Label></td>
                        </tr>
                    </div>
                </AlternatingItemTemplate>
                <EmptyDataTemplate>
                    抱歉,没有数据
                </EmptyDataTemplate>
            </asp:ListView>
            
    </div>
    </form>
</body>
</html>
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2021-07-07
  • 2021-09-15
  • 2021-12-11
猜你喜欢
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2022-02-14
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
相关资源
相似解决方案