This data source is divided into two parts, one is to pull out data from the data class, and then in this data source for paging parameters and page paging secondary control operation! There are three controls on the front page, one Drop-down list, and two linkbutton!
The following fill () method call is very simple, in the page to be bound to the place to write fill () on it, hehe! But be sure to write oh, such as the page after the action is performed!
The following is the DS method in the DB class
public static DataTable ds (string que)
{//Returns a data table loaded with SQL development 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 method below is this
private void Fill ()
{//method , because there will be multiple bindings in the page
//Here to set a hidden label, with and save 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 go in, determine the data source data source, a bit around it, hehe
Ps. AllowPaging = true;//Allow paging
Ps. PageSize = 2;//Set Number of pages
Ps. CurrentPageIndex = cup-1;
if (! IsPostBack)
{//To determine if the page is loaded for the first time
for (int i = 1; I <= PS. PageCount; i++)
{//Loop page number
Pageddl. Items.Add (i.ToString ());
}
}
The following is mainly to control whether the page up and down button is
PageUp. Enabled = true;
PageDown. Enabled = true;
if (Ps. Isfirstpage)
{//If is the front page, the button on the page is not available
PageUp. Enabled = false;
}
if (Ps. Islastpage)
{//If the last page, the Next button is not available
PageDown. Enabled = false;
}
Sets the currently selected value of the page number Drop-down menu
Pageddl. Selecteditem.text = Cup. ToString ();
Can finally bind to DataList.
Datalist1.datasource = PS;
Datalist1.datakeyfield = "id";
Datalist1.databind ();
}
And the following is the process of paging events
protected void Pageddl_selectedindexchanged (object sender, EventArgs e)
{//Page number Pull-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)
{//Up-page events
Pagelbl. Text = convert.tostring (Convert.ToInt32 (PAGELBL). Text)-1);
Fill ();
}