The ninth day of ASP.net

Source: Internet
Author: User

Objective: To learn how to use the DATAGRID to display data by PAGE

Although the page display efficiency of the DATAGRID is not very high, in any case, it is the most convenient page display, and it is quite simple and practical for making a message book. There is also an important requirement for enabling the paging function. The paging function can be enabled only when the data source of the DATADRID control implements the ICOLLECTION interface. DATAREADER does not have this interface, so it must be replaced by DATATABLE.
<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>
<Html>
<Body>
<Asp: DataGrid
Id = "dgrdMain"
Cellpadding = "1"
Showheader = "true"
Borderwidth = "0"
Allowpaging = "true" enable Paging
Pagesize = "3" each page displays three records
Onpageindexchanged = "dgrdMain_pageindexchanged" Call the function on page X to dgrdMain_PageIndexChanged ()
Runat = "server"
/>
</Body>
</Html>

<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>
<Html>
<Body>
<Asp: DataGrid
Id = "dgrdMain"
Cellpadding = "1"
Showheader = "true"
Borderwidth = "0"
Allowpaging = "true" enable Paging
Pagesize = "3" each page displays three records
Onpageindexchanged = "dgrdMain_pageindexchanged" Call the function on page X to dgrdMain_PageIndexChanged ()
Runat = "server"
/>
</Body>
</Html>

This is the simplest page. You can use the pagestyle-mode = "nextprev/numericpages" parameter to set whether to display the previous page, the next page, or directly select the number of the page to redirect the page. For the former, we can use pagestyle-nextpagetext to set the text containing the next page Link, and use pagestyle-prevpagetext to set the text containing the previous page Link; if it is the latter, we can use PagerStyle-PageButtonCount to set the number of pages displayed before the ellipsis (10 by default)

Let's talk about the SESSION and COOKIE tomorrow.
Http://blog.csdn.net/byebye8742/archive/2004/02/02/19501.aspx

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.