zoukankan      html  css  js  c++  java
  • ListView结合DataPager分页

    页面代码如下:
    <asp:ListView runat="server" ID="_simpleTableListView">
      <LayoutTemplate>
        <table>
          <thead>
            <tr>
                 <th id="Th1" runat="server">
                     ID</th>
                 <th id="Th2" runat="server">
                     StudentID</th>
                 <th id="Th3" runat="server">
                     Name</th>
                 <th id="Th4" runat="server">
                     Math</th>
                 <th id="Th5" runat="server">
                     English</th>
                 <th id="Th6" runat="server">
                     Chinese</th>
            </tr>
          </thead>
          <tbody>
            <asp:PlaceHolder runat="server" ID="itemPlaceholder" />
          </tbody>
        </table>
      </LayoutTemplate>
      <ItemTemplate>
        <tr>
            <td>
                <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
            </td>
            <td>
                <asp:Label ID="StudentIDLabel" runat="server" Text='<%# Eval("StudentID") %>' />
            </td>
            <td>
                <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
            </td>
            <td>
                <asp:Label ID="MathLabel" runat="server" Text='<%# Eval("Math") %>' />
            </td>
            <td>
                <asp:Label ID="EnglishLabel" runat="server" Text='<%# Eval("English") %>' />
            </td>
            <td>
                <asp:Label ID="ChineseLabel" runat="server" Text='<%# Eval("Chinese") %>' />
            </td>
        </tr>
      </ItemTemplate>
    </asp:ListView>
    <asp:DataPager ID="DataPager2" runat="server"
        PagedControlID="_simpleTableListView" PageSize="2"
        onprerender="DataPager2_PreRender">
        <Fields>
            <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
                ShowLastPageButton="True" />
        </Fields>
    </asp:DataPager>
    后台代码:
        protected void DataPager2_PreRender(object sender, EventArgs e)
        {
            BindData();
        }
     private void BindData()
        {
      using (OleDbConnection conn = new OleDbConnection(OleDbHelper.ConnectionString))
      {
       string sql = "select * from studentscore";
       OleDbDataAdapter dp=new OleDbDataAdapter(sql,conn);
       DataTable dt = new DataTable();
       dp.Fill(dt);
       _simpleTableListView.DataSource = dt;
       _simpleTableListView.DataBind();
      }
        }
    注意:使用本方法,不需要在页面的Page_Load事件中绑定数据到ListView控件,
    否则分页会有问题。

    第2种方法:
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
     protected void _simpleTableListView_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            DataPager2.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
            BindData();
        }

  • 相关阅读:
    jquery 停止animate动画,并且回复最初状态
    php mysql实体字符
    ECSHOP MYSQL 公用类库中的autoExecute方法
    ecshop 订单编号 get_order_sn
    ecshop 调用收货地址
    init.php 建立自己的前端共享文件
    php 生成随机字符串 abcdeft....789
    ecshop 订单-》订单状态 2
    ecshop后台,listtable.js使用
    ecshop Admin后台商品列表处(上架、下架、精品...取消精品)增加操作
  • 原文地址:https://www.cnblogs.com/zhouhb/p/3018489.html
Copyright © 2011-2022 走看看