Listview+DataPager分页

为objectdatasource指定数据源

前端代码

<asp:ObjectDataSource ID="datasource" TypeName="PageTest.PersonInfo"
 SelectMethod="GetMessage" runat="server"> </asp:ObjectDataSource>

<asp:ListView ID="ListView1" runat="server" DataSourceID="datasource">

中间绑定字段我就不粘上来了

</asp:ListView>

<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1"
        PageSize="2">
        <Fields>
            <asp:NextPreviousPagerField ButtonType="Button"  ShowFirstPageButton="True" ShowNextPageButton="false"/>
            <asp:NumericPagerField />
            <asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="true"
              ShowPreviousPageButton="false"   ShowLastPageButton="true" />
        </Fields>
    </asp:DataPager>

后台代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace PageTest
{
    public class PersonInfo
    {
        public static DataTable GetMessage()
        {
            string Connect = ConfigurationManager.AppSettings["huyonghong"].ToString();
            SqlConnection sc = new SqlConnection(Connect);
            sc.Open();
            SqlCommand cm = new SqlCommand("select * from PersonInfo where PersonId>0");
            cm.Connection = sc;
            DataSet ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter(cm);
            sda.Fill(ds, "huyonghong");
            DataTable dt = ds.Tables["huyonghong"];
            return dt;
        }
    }
}

posted @ 2013-05-19 13:12  BicycleBoy  阅读(166)  评论(0编辑  收藏  举报