none
ListView结合DataPager分页?不是拖数据源控件。 RRS feed

  • 问题

  •  ListView结合DataPager分页,如何分页?不是拖数据源控件。自己产生DataTable,绑定到ListView的。如何分页?   ListView或者DataPager没有类似Gridview的PageIndexChaning事件吗,程序员可以把分页的代码写到相应的事件中。
        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();
            }

        }
       <asp:ListView runat="server" ID="_simpleTableListView" 
                onpagepropertieschanged="_simpleTableListView_PagePropertiesChanged">
      <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">
                <Fields>
                    <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                        ShowLastPageButton="True" />
                </Fields>
            </asp:DataPager>
    2013年4月12日 9:02

答案

全部回复