为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;
}
}
}