DataGrid page instance (transferred from the wonderful world of Mengxian)

zhaozj2021-02-16  99

ASP.NET page

<%

@ Page Language

=

"

C #

"

EnableViewState

=

"

True

"

Codebehind

=

"

DataGridPaging.aspx.cs

"

Autoeventwireup

=

"

False

"

Inherits

=

"

Emeng.exam.dataGridpaging.DataGridPaging

"

%>

DOCTYPE HTML PUBLIC

"

- // W3C // DTD HTML 4.0 Transitional // EN

"

>

<

HTML

>

<

HEAD

>

<

Meta Content

=

"

Visual Basic 7.0

"

Name

=

"

Code_Language

"

>

<

Meta Content

=

"

JavaScript

"

Name

=

"

VS_DEFAULTCLIENTScript

"

>

<

Meta Content

=

"

http://schemas.microsoft.com/intellisense/ie5

"

Name

=

"

vs_targetschema

"

>

HEAD

>

<

Body ms_positioning

=

"

Gridlayout

"

>

<

Form ID

=

"

Form1

"

Runat

=

"

Server

"

>

<

ASP: DataGrid ID

=

"

MyDataGrid

"

Runat

=

"

Server

"

AutogenerateColumns

=

"

False

"

Horizontalalign

=

"

Center

"

AlternatingItemStyle

-

Backcolor

=

"

#eeeeee

"

HEADERSTYLE

-

Backcolor

=

"

#aaaadd

"

Font

-

Size

=

"

8PT

"

Font

-

Name

=

"

Verdana

"

Cellspacing

=

"

0

"

Cellpadding

=

"

3

"

Gridlines

=

"

Both

"

Borderwidth

=

"

1

"

Bordercolor

=

"

Black

"

ONPAGEIDEXCHANGED

=

"

MyDataGrid_page

"

Pagerstyle

-

Horizontalalign

=

"

Right

"

Pagerstyle

-

Mode

=

"

NumericPages

"

PageSize

=

"

5

"

Allowpaging

=

"

True

"

>

<

AlternatingItemStyle Backcolor

=

"

#Eeeeee

"

>

AlternatingItemStyle

>

<

Headerstyle Backcolor

=

"

#Aaaadd

"

Font

-

Bold

=

"

True

"

Horizontalalign

=

"

Center

"

>

HEADERSTYLE

>

<

Pagerstyle Horizontalalign

=

"

Right

"

Mode

=

"

NumericPages

"

>

Pagerstyle

>

<

Columns

>

<

Asp: boundcolumn headertext

=

"

title

"

Datafield

=

"

Title

"

HEADERSTYLE

-

Width

=

"

480px

"

>

ASP: BoundColumn

>

<

Asp: boundcolumn headertext

=

"

Dates

"

Datafield

=

"

CreateDate

"

DataFormatString

=

"

{0: YYYY-MM-DD HH: mm: ss}

"

>

ASP: BoundColumn

>

Columns

>

ASP: DATAGRID

>

<

P Style

=

"

Font-size: 9PT

"

Align

=

"

Center

"

>

<

ASP: Label ID

=

"

LBLPAGECUNT

"

Runat

=

"

Server

"

>

ASP: Label

> &

NBSP;

<

ASP: Label ID

=

"

lblcurrentIndex

"

Runat

=

"

Server

"

>

ASP: Label

>

<

ASP: LINKBUTTON ID

=

"

btnfirst

"

Onclick

=

"

PagerButtonClick

"

Runat

=

"

Server

"

Font

-

Name

=

"

Verdana

"

Font

-

Size

=

"

8PT

"

Forecolor

=

"

Navy

"

Commandargument

=

"

0

"

>

ASP: LINKBUTTON

> &

NBSP;

<

ASP: LINKBUTTON ID

=

"

Btnprev

"

Onclick

=

"

PagerButtonClick

"

Runat

=

"

Server

"

Font

-

Name

=

"

Verdana

"

Font

-

Size

=

"

8PT

"

Forecolor

=

"

Navy

"

Commandargument

=

"

Prev

"

>

ASP: LINKBUTTON

> &

NBSP;

<

ASP: LINKBUTTON ID

=

"

btnnext

"

Onclick

=

"

PagerButtonClick

"

Runat

=

"

Server

"

Font

-

Name

=

"

Verdana

"

Font

-

Size

=

"

8PT

"

Forecolor

=

"

Navy

"

Commandargument

=

"

NEXT

"

>

ASP: LINKBUTTON

> &

NBSP;

<

ASP: LINKBUTTON ID

=

"

btnlast

"

Onclick

=

"

PagerButtonClick

"

Runat

=

"

Server

"

Font

-

Name

=

"

Verdana

"

Font

-

Size

=

"

8PT

"

Forecolor

=

"

Navy

"

Commandargument

=

"

last

"

>

ASP: LINKBUTTON

>

p

>

FORM

>

Body

>

HTML

>

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

Rear code:

Using

System;

Using

System.collections;

Using

System.componentmodel;

Using

System.data;

Using

System.Data.OleDb;

Using

System.drawing;

Using

System.Web;

Using

System.Web.SessionState;

Using

System.Web.ui;

Using

System.Web.ui.WebControls;

Using

System.Web.ui.htmlControls;

Namespace

EMENG.EXAM.DATAGRIDPAGING

{/ ** ////

/// DataGridPaging Summary Description.

/// public class DataGridPaging: System.Web.UI.Page {protected System.Web.UI.WebControls.DataGrid MyDataGrid; protected System.Web.UI.WebControls.Label lblPageCount; protected System.Web.UI. WebControls.Label lblCurrentIndex; protected System.Web.UI.WebControls.LinkButton btnFirst; protected System.Web.UI.WebControls.LinkButton btnPrev; protected System.Web.UI.WebControls.LinkButton btnNext; protected System.Web.UI.WebControls. LinkButton btnLast; private OleDbConnection cn = new OleDbConnection (); private void Page_Load (object sender, System.EventArgs e) {// Put user code to initialize the page here btnFirst.Text = "most Home"; btnPrev.Text = " Previous page "; btnnext.text =" next page "; btnlast.text =" last page "; OpenDatabase (); bindgrid ();} private void OpenDatabase () {cn.connectionstring =" provike = microsoft.jet. OLEDB.4.0; Data Source = " Server.mAppath (" xxxx.mdb "); cn.open ();} private void showstats () {lblcurrentIndex.text =" 第DataGrid.currentpageIndex 1) .tostring () "Page"; lblpagecount.text = "total" myDataGri D.PageCount.toString () "page";} public void PagerButtonClick (Object sender, eventargs e) {string arg = (linkbutton) sender .commandargument.toString (); switch (arg) {copy "next": if (MyDataGrid.CurrentPageIndex <(MyDataGrid.PageCount - 1)) {MyDataGrid.CurrentPageIndex = 1;} break; case "prev": if (MyDataGrid.CurrentPageIndex> 0) {MyDataGrid.CurrentPageIndex - = 1;} break; case "Last": mydatagrid.currentpageindex = (MyDataGrid.pagecount - 1); break; default: mydatagrid.currentpageIndex =

转载请注明原文地址:https://www.9cbs.com/read-10890.html

New Post(0)