The Nineth day of the 10 day society asp.net

Source: Internet
Author: User
ASP.net learning Purpose: Learn to use the DataGrid paging display

Although the DataGrid's paging display efficiency is not high, but anyway, it is the most convenient paging display, for making a guest book is quite simple and practical. There is also an important requirement for paging functionality to enable paging functionality only if the Datadrid control's data source implements the ICollection interface, and DataReader does not have this interface, so you must use a DataTable instead.
<script runat= "Server" language= "C #" >
void Page_Load ()
{
String strconnection= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=";
Strconnection+=server.mappath ("Guestbook.mdb");
OleDbConnection objconnection=new OleDbConnection (strconnection);
OleDbDataAdapter objdataadapter=new OleDbDataAdapter ("SELECT * from Guestbook", objconnection);
DataSet objdataset=new DataSet ();
Objdataadapter.fill (objdataset);
Dgrdmain.datasource=objdataset;
Dgrdmain.databind ();
}
void Dgrdmain_pageindexchanged (Object sender, DataGridPageChangedEventArgs e)
{
Dgrdmain.currentpageindex = E.newpageindex;
DataBind ();
}
</script>
<body>
<asp:datagrid
Id= "Dgrdmain"
cellpadding= "1"
Showheader= "true"
Borderwidth= "0"
Allowpaging= "True" enables paging functionality
Pagesize= "3" Each page shows three records
Onpageindexchanged= "dgrdmain_pageindexchanged" calls the function of page X as dgrdmain_pageindexchanged ()
runat= "Server"
/>
</body>



--------------------------------------------------------------------------------

<script runat= "Server" Language= "VB" >
Subpage_load
Dim objconnection As OleDbConnection
Dim objdataadapter As OleDbDataAdapter
Dim objdataset As DataSet
Objconnection=new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" +Server.MapPath ("Guestbook.mdb") ))
Objdataadapter=new OleDbDataAdapter ("SELECT * from Guestbook", objconnection)
Objdataset=new DataSet
Objdataadapter.fill (Objdataset)
Dgrdmain.datasource=objdataset
Dgrdmain.databind ()
End Sub
Sub Dgrdmain_pageindexchanged (sender as object,e as DataGridPageChangedEventArgs)
Dgrdmain.currentpageindex = E.newpageindex
DataBind
End Sub
</script>
<body>
<asp:datagrid
Id= "Dgrdmain"
cellpadding= "1"
Showheader= "true"
Borderwidth= "0"
Allowpaging= "True" enables paging functionality
Pagesize= "3" Each page shows three records
Onpageindexchanged= "dgrdmain_pageindexchanged" calls the function of page X as dgrdmain_pageindexchanged ()
runat= "Server"
/>
</body>

This is the simplest pagination, we can use the parameter pagestyle-mode= "Nextprev/numericpages" to set is to display the previous page, the next page or directly select the number of pages to achieve page jump. If it is the former we can use Pagestyle-nextpagetext to set the text containing the next page link, with Pagestyle-prevpagetext to set the text that contains the previous page link If it is the latter we can use Pagerstyle-pagebuttoncount to set the number of page numbers displayed before the ellipsis is used (default is 10)

Let's talk about the session and cookies tomorrow.




Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.