Personalized pagination (2) in the last section, we did not see the overall structure, this section, I put the code all posted out, we have a good look.
<%@ Page language= "C #"%>
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.SQL"%>
<script language= "C #" runat= "Server" >
void Page_Load (Object sender, EventArgs e)
{
file:// whether to hide Pagerstyle-mode
if (chk1. Checked)
{
Mydatagrid.pagerstyle.visible=true;
}
Else
{
Mydatagrid.pagerstyle.visible=false;
}
Bindgrid ();
}
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", Myconnect ION);
DataSet ds= new DataSet ();
Mydatasetcommand.filldataset (ds, "Admin_enter");
Return DS. tables["Admin_enter"]. DefaultView;
}
void Pagerbuttonclick (Object sender, EventArgs e)
{
file://obtained 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
file://this page value
Mydatagrid.currentpageindex = arg. ToInt32 ();
Break
}
Bindgrid ();
}
void Mydatagrid_page (Object sender, DataGridPageChangedEventArgs e)
{
file:// The method of pressing the numbers
Bindgrid ();
}
void Bindgrid ()
{
file://will DataView bound to the DataGrid.
Mydatagrid.datasource = CreateDataSource ();
Mydatagrid.databind ();
Showstats ();
}
void Showstats ()
{
file://Display page information
Lblcurrentindex.text = "Current page is:" + ((int) mydatagrid.currentpageindex+1);
Lblpagecount.text = "Total number of pages is:" + mydatagrid.pagecount;
}
</script>
<body>
<form runat=server>
<asp:datagrid id= "Mydatagrid" runat= "Server"
Allowpaging= "True"
Pagesize= "10"
Pagerstyle-mode= "NumericPages"
Pagerstyle-horizontalalign= "Right"
Onpageindexchanged= "Mydatagrid_page"
Bordercolor= "BLACK"
Borderwidth= "1"
Gridlines= "Both"
Cellpadding= "3"
cellspacing= "0"
Font-name= "Verdana"
Font-size= "8pt"
Headerstyle-backcolor= "#aaaadd"
Alternatingitemstyle-backcolor= "#eeeeee"
Autogeneratecolumns= "false"
>
<property name= "Columns" >
<asp:boundcolumn headertext= "Studio member" datafield= "enter_id"/>
<asp:boundcolumn headertext= "Landing Time" datafield= "Enter_time"/>
</property>
</ASP:DataGrid>
<p>
<asp:linkbutton id= "Btnfirst" runat= "Server"
text= "Home"
commandargument= "0"
Forecolor= "Navy"
Font-name= "Verdana" font-size= "8pt"
/>
<asp:linkbutton id= "Btnprev" runat= "Server"
text= "front page"
Commandargument= "Prev"
Forecolor= "Navy"
Font-name= "Verdana" font-size= "8pt"
/>
<asp:linkbutton id= "Btnnext" runat= "Server"
text= "Back Page"
Commandargument= "Next"
Forecolor= "Navy"
Font-name= "Verdana" font-size= "8pt"
/>
<asp:linkbutton id= "Btnlast" runat= "Server"
Text= "Last"
Commandargument= "Last"
Forecolor= "Navy"
Font-name= "Verdana" font-size= "8pt"
/>
<p>
<asp:checkbox id= "Chk1" runat= "Server"
Text= "Show built in pages"
Font-name= "Verdana"
Font-size= "8pt"
Autopostback= "true"
/>
<p>
<table bgcolor= "#eeeeee" cellpadding= "6" ><tr><td nowrap><font face= "Verdana" size= "-2" >
<asp:label id= "Lblcurrentindex" runat= "Server"/><br>
<asp:label id= "Lblpagecount" runat= "Server"/><br>
</font></td></tr></table>
</form>
</body>
The above is the whole source code, after the execution of the display is:
Figure 14-1
Press any key, such as "last Page"
Figure 14-2
See, our program is directly to the last page, that is, page 5th, we can see in the "Current page" below:)
Let's Click the check box "show built-in Pages" to see:
Figure 14-3
Look, the small numbers we saw in the first two sections also came out: