The pagination we talked about was just a way to implement pagination by modifying the properties of the DataGrid, which has the benefit
, the biggest is simple, hehe, do not have to worry about, pagination is how to produce.
But it is also flawed and does not produce the kinds of styles we want to do as we imagine.
There is no way to personalize the function, only to do it yourself, hehe.
The first step is to import the required namespaces. The following example, in fact, I also found from abroad
, plus some personal stuff, and then Chinese, hehe. The mood is very good today, I even the label color to show everybody
Here it comes. Oh, more conducive to everyone to see the program.
From the example above we can see that clicking the LinkButton control onclick triggers the Pagebuttonclick event,
The DataGrid page onpageindexchanged change triggers the Mydatagrid_page event, and we'll be
Is the code to write these two events
Here is the first query of the database information, expressed in a function, because often used:), I opened the table, uh
Oh, it's our studio Admin login log (and we sold some of our studio secrets to everyone).
ICollection CreateDataSource ()
{
/*
Read the database information and get the DataView
*/
SqlConnection myconnection = new
SqlConnection ("SERVER=LOCALHOST;UID=SA;PWD=123456;DATABASE=ASPCN");
Sqldatasetcommand Mydatasetcommand = new Sqldatasetcommand ("SELECT * FROM
Admin_enter ORDER BY enter_time Desc ", MyConnection);
DataSet ds= new DataSet ();
Mydatasetcommand.filldataset (ds, "Admin_enter");
Return DS. tables["Admin_enter"]. DefaultView;
}
And then there's the Page_Load function, where you're basically deciding whether to show the paging numbers that come with the DataGrid.
, using the Pagestyle Visible property:
Here is the Pagerbuttonclick that handles the Click event, this is our core part, in fact we operate only
is the CurrentPageIndex property of the DataGrid. If CurrentPageIndex is less than pagecount then there is a next page
, if CurrentPageIndex is greater than 0, the previous page is represented.
void Pagerbuttonclick (Object sender, EventArgs e)
{
Get the LinkButton parameter value
String arg = ((LinkButton) sender). CommandArgument;
Switch (ARG)
{
Case ("Next"):
if (Mydatagrid.currentpageindex < (mydatagrid.pagecount-1))
Mydatagrid.currentpageindex + +;
Break
Case ("prev"):
if (Mydatagrid.currentpageindex > 0)
Mydatagrid.currentpageindex--;
Break
Case ("Last"):
Mydatagrid.currentpageindex = (mydatagrid.pagecount-1);
Break
Default
Value of this page
Mydatagrid.currentpageindex = arg. ToInt32 ();
Break
}
Bindgrid ();
}
Here is Mydatagrid_page, the main action is to call the Bindgrid function to give the data to the DataGrid display:
void Mydatagrid_page (Object sender, DataGridPageChangedEventArgs e)
{
How to handle numbers
Bindgrid ();
}
Finally there are two functions that they function, which I have commented on:
void Bindgrid ()
{
Bind DataView to the DataGrid
Mydatagrid.datasource = CreateDataSource ();
Mydatagrid.databind ();
Showstats ();
}
void Showstats ()
{
Display page Information
Lblcurrentindex.text = "Current page is:" +
((int) mydatagrid.currentpageindex+1);
Lblpagecount.text = "Total number of pages is:" + mydatagrid.pagecount;
}
So far, our personalized page has been completed (all code and display to see the section), our general thinking on
is to use the LinkButton control as a page-flipping flag, by judging the commandargument value of the LinkButton,
As the CurrentPageIndex property of the DataGrid to achieve the effect of paging.
If you don't understand the structure in this section, see the entire code in the next section and the example.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.