This data source is divided into two parts. One is to call the data from the data class, and then operate the paging parameters and page paging auxiliary controls in this data source! There are three controls on the front to control page turning, a drop-down list, and two LinkButtons!
For more methods of data manipulation in classes, please see http://thcjp.cnblogs.com/archive/2006/06/18/428775.html.
The fill() method call is very simple and needs to be re-bound on the page. Just write fill() somewhere, haha! But it must be written, for example, after the page turning action is executed!
The following is the ds method in the db class
public static DataTable ds(string que)
{//Return a data table loaded with SQL-defined messages,
OleDbConnection con = odb.con();
OleDbDataAdapter oda = new OleDbDataAdapter();
oda.SelectCommand=new OleDbCommand(que,con);
DataSet ds = new DataSet();
oda.Fill(ds,"thc");
return ds.Tables["thc"];
con.Close();
}The data source used by the following method is the one above
private void fill()
{//A way to do it, because there will be multiple bindings in the page
//Set a hidden Label here to store the current page index
int cup = Convert.ToInt32(pagelbl.Text);
PagedDataSource ps = new PagedDataSource();//NEW a paging data source
ps.DataSource = odb.ds("select * from guest order by id desc").DefaultView;//Send a SQL statement to determine the data source of the data source. This is a bit convoluted, haha
ps.AllowPaging = true;//Allow paging
ps.PageSize = 2;//Set the number of pages
ps.CurrentPageIndex = cup-1;
if (!IsPostBack)
{//Determine whether the page is loaded for the first time
for (int i = 1; i <= ps.PageCount; i++)
{//Loop out page numbers
pageddl.Items.Add(i.ToString());
}
}
//The following is mainly to control whether the page up and down buttons are enabled.
pageup.Enabled = true;
pagedown.Enabled = true;
if (ps.IsFirstPage)
{//If it is the front page, the previous page button is unavailable
pageup.Enabled = false;
}
if (ps.IsLastPage)
{//If it is the last page, the next page button is unavailable
pagedown.Enabled = false;
}
//Set the currently selected value of the page number drop-down menu
pageddl.SelectedItem.Text = cup.ToString();
//Finally can be bound to DataList
DataList1.DataSource = ps;
DataList1.DataKeyField = "id";
DataList1.DataBind();
}
Next is the processing of page turning events
protected void pageddl_SelectedIndexChanged(object sender, EventArgs e)
{//Page number drop-down menu event
pagelbl.Text = pageddl.SelectedItem.Text.ToString();
fill();
}
protected void pagedown_Click(object sender, EventArgs e)
{//Next page event
pagelbl.Text = Convert.ToString(Convert.ToInt32(pagelbl.Text)+1);
fill();
}
protected void pageup_Click(object sender, EventArgs e)
{//Previous page event
pagelbl.Text = Convert.ToString(Convert.ToInt32(pagelbl.Text)-1);
fill();
}