DataList分页代码(急急)
最好是用PageDataSource类写的
------解决方案--------------------using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
class DataList分页
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
FillData();
}
}
static PagedDataSource Pds;
void FillData()
{
SqlConnection Conn = new SqlConnection( "Data Source=192.168.1.30;database=Ticket_Info_Data;UID=sa;Password=sa;Persist Security Info=True; ");
Conn.Open();
SqlDataAdapter Sda = new SqlDataAdapter( "select * from DomesticFlight ", Conn);
DataSet Ds = new DataSet();
Sda.Fill(Ds);
Pds = new PagedDataSource();
Pds.DataSource = Ds.Tables[0].DefaultView;
Pds.AllowPaging = true;
Pds.PageSize = 6;
this.DataList1.DataSource = Pds;
this.DataList1.DataBind();
Conn.Close();
}
//下一页
protected void LinkButton2_Click(object sender, EventArgs e)
{
Pds.CurrentPageIndex++;
this.DataList1.DataSource = Pds;
this.DataList1.DataBind();
}
//上一页
protected void LinkButton1_Click(object sender, EventArgs e)
{
Pds.CurrentPageIndex--;
this.DataList1.DataSource = Pds;
this.DataList1.DataBind();
}
}