Contact ASP.Net(14 intimately)
Tuesday, March 03, 2009 by rain
An everybody did not see total construction,This one,I stick code entirely come out,Everybody looks well.
%26lt;%@ Page Language= %26quot;C#%26quot; %%26gt;
%26lt;%@ Import Namespace= %26quot;System.Data%26quot; %%26gt;
%26lt;%@ Import Namespace= %26quot;System.Data.SQL%26quot; %%26gt;
%26lt;html%26gt;
%26lt;script Language= %26quot;C#%26quot; Runat= %26quot;server%26quot; %26gt;
Void Page_Load(Object Sender, eventArgs E)
{
/ / whether does judgement conceal PagerStyle-Mode
If (chk1.Checked)
{
MyDataGrid.PagerStyle.Visible=true;
}
Else
{
MyDataGrid.PagerStyle.Visible=false;
}
BindGrid();
}
ICollection CreateDataSource()
{
/ *
The news that reads access to occupy a library,Obtain 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;
}
Void PagerButtonClick(Object Sender, eventArgs E)
{
/ / the ginseng that obtains LinkButton is numeric
String Arg = ((LinkButton)sender).CommandArgument;
Switch(arg)
{
Case ("next" ) :
If (MyDataGrid.CurrentPageIndex%26lt;(MyDataGrid.PageCount - 1) )
MyDataGrid.CurrentPageIndex ++;
Break;
Case ("prev" ) :
If (MyDataGrid.CurrentPageIndex%26gt;0)
MyDataGrid.CurrentPageIndex- - ;
Break;
Case ("last" ) :
MyDataGrid.CurrentPageIndex = (MyDataGrid.PageCount - 1);
Break;
Default:
/ / this page cost
MyDataGrid.CurrentPageIndex = Arg.ToInt32();
Break;
}
BindGrid();
}
Void MyDataGrid_Page(Object Sender, dataGridPageChangedEventArgs E)
{
/ / processing presses digital method
BindGrid();
}
Void BindGrid()
{
/ / bind DataView go up to DataGrid surely
MyDataGrid.DataSource = CreateDataSource();
MyDataGrid.DataBind();
ShowStats();
}
Void ShowStats()
{
/ / indication page information
Number of current page of LblCurrentIndex.Text = " is:"+ ((Int)MyDataGrid.CurrentPageIndex+1);
Number of total page of LblPageCount.Text = " is:"+ MyDataGrid.PageCount;
}
%26lt;/script%26gt;
%26lt;body%26gt;
The ^%26amp;^%26lt;/font%26gt;%26lt;/h3%26gt; of the example that distribute a page of individuation of %26lt;h3%26gt;%26lt;font Face= %26quot;Verdana%26quot; %26gt;
%26lt;form Runat=server%26gt;
%26lt;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 "
%26gt;
%26lt;property Name= %26quot;Columns%26quot; %26gt;
%26lt;asp:B%26quot; DataField= %26quot;Enter_ID%26quot; /%26gt; of member of atelier of OundColumn HeaderText= %26quot;
%26lt;asp:BOundColumn HeaderText= %26quot; lands time %26quot; DataField= %26quot;Enter_Time%26quot; /%26gt;
%26lt;/property%26gt;
%26lt;/ASP:DAtaGrid%26gt;
%26lt;p%26gt;
%26lt;asp:LInkButton Id= "btnFirst" Runat= "server "
Text= " home page "
CommandArgument= "0 "
ForeColor= "navy "
Font-Name= "verdana" Font-size= "8pt "
OnClick= "PagerButtonClick "
/ %26gt;
%26lt;asp:LInkButton Id= "btnPrev" Runat= "server "
The page before Text= " "
CommandArgument= "prev "
ForeColor= "navy "
Font-Name= "verdana" Font-size= "8pt "
OnClick= "PagerButtonClick "
/ %26gt;
%26lt;asp:LInkButton Id= "btnNext" Runat= "server "
The page after Text= " "
CommandArgument= "next "
ForeColor= "navy "
Font-Name= "verdana" Font-size= "8pt "
OnClick= "PagerButtonClick "
/ %26gt;
%26lt;asp:LInkButton Id= "btnLast" Runat= "server "
Page of Text= " end "
CommandArgument= "last "
ForeColor= "navy "
Font-Name= "verdana" Font-size= "8pt "
OnClick= "PagerButtonClick "
/ %26gt;
%26lt;p%26gt;
%26lt;asp:CHeckbox Id= "chk1" Runat= "server "
Text= " shows inside the page number of buy "
Font-Name= "Verdana "
Font-Size= "8pt "
AutoPostBack= "true "
/ %26gt;
%26lt;p%26gt;
%26lt;table Bgcolor= %26quot;#eeeeee%26quot; Cellpadding= %26quot;6%26quot; %26gt;%26lt;tr%26gt;%26lt;td Nowrap%26gt;%26lt;font Face= %26quot;Verdana%26quot; Size= %26quot;-2%26quot; %26gt;
%26lt;asp:LAbel Id= %26quot;lblCurrentIndex%26quot; Runat= %26quot;server%26quot; /%26gt;%26lt;br%26gt;
%26lt;asp:LAbel Id= %26quot;lblPageCount%26quot; Runat= %26quot;server%26quot; /%26gt;%26lt;br%26gt;
%26lt;/font%26gt;%26lt;/td%26gt;%26lt;/tr%26gt;%26lt;/table%26gt;
%26lt;/form%26gt;
%26lt;/body%26gt;
%26lt;/html%26gt;
Whole source code is above,The indication after carrying out is:
Graph 14-1
It is informal to press a key,For instance " end page "
Graph 14-2
Look,Our program received last page continuously,Namely the 5th page,We count " to be able to see in the " current page below:)
We click " to show again inside the page of buy counts " this answer choose casing,Look:
Graph 14-3
Look,Those before us two small numbers that see also came out:)