Feed on
Subscription

Contact ASP.Net(13 intimately)

Cent page of individuation comes true

The cent page that tells before us,Just be to pass the attribute of modification DataGrid to realize minute of page,Have such profit so,The biggest is simple,Breathe out ah,Need not worry about at all,Distributing a page is how arise.

But it is likewise faulty,The produces all sorts of our need type that cannot envisage according to us.

Without method,Think personalized function,Already started work oneself only will do,Breathe out ah.

We one step by step come,It is to guide above all of need name a space.The example below,Also be me actually from what abroad searchs,Plus dot individual east east,Again Chinese change,Breathe out ah.The mood is very good today,I show even label color to everybody came.Breathe out ah,More benefit sees a program at everybody.

%26lt;%@ Page Language= %26quot;C#%26quot; %%26gt;
%26lt;%@ Import Namespace= %26quot;System.Data%26quot; %%26gt;
%26lt;%@ Import Namespace= %26quot;System.Data.SQL%26quot; %%26gt;

We look first,Our Web accuses what be,Reading code again is how write,Such good comparison:)

%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;

From the example above we can see those who click LinkButton to accuse an OnClick to spark is PageButtonClick incident, what change of DataGrid page OnPageIndexChanged sparks is MyDataGrid_Page incident,We want to write the code of these two incident namely namely later

The information that the database that wants inquiry first is below,Express with a function,Because often be used:) , the table that I open,Breathe out ah,The disembarkation that is our atelier precinct record sheet (breath out the secret that sold a dot our studio again to give authority)

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;
}

Next in it is Page_Load function, basically be to judge the number of those minutes of page that whether shows DataGrid is taken oneself here,The Visible attribute that those who use is PageStyle:

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();
}

The PagerButtonClick that processing clicks incident is below,The core part that this is us,The also is DataGrid only CurrentPageIndex property that actually we operate.If CurrentPageIndex is less than PageCount to have below one page,If CurrentPageIndex is more than 0 before expressing to have one page.

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();
}

MyDataGrid_Page is below, main operation is to transfer BindGrid function,With giving data DataGrid shows:

Void MyDataGrid_Page(Object Sender, dataGridPageChangedEventArgs E)
{
/ / processing presses digital method
BindGrid();
}

Finally is two function,Their action,I annotate:)

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;
}

Hereto,Our personalized page had been finished (whole code and show see a red-letter day) ,We total thought uses LinkButton to accuse namely as the mark banner that turns over a page,Through judging the CommandArgument of LinkButton to be worth,The CurrentPageIndex property that operates DataGrid,The effect that reverses a page in order to achieve.

If everybody looks in this section,do not know a structure,Consult please below one whole code and give typical examples.

 
Related:

    Submit: