A fully functional DataGrid page example

zhaozj2021-02-16  52

DataGridPaging.aspx.cs

<-! StartFragment -> 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> /// DataGridPaging Summary> /// 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 =

System.Convert.ToInt32 (arg); break;} BindGrid (); ShowStats ();} public void BindGrid () {OleDbConnection myConnection = cn; DataSet ds = new DataSet (); OleDbDataAdapter adapter = new OleDbDataAdapter ( "Select Title, CreateDate from Document ", myConnection); adapter.Fill (ds," Document. "); MyDataGrid.DataSource = ds.Tables [" Document "] DefaultView; MyDataGrid.DataBind (); ShowStats ();} public void MyDataGrid_Page (object sender, DataGridPageChangedEventArgs e) {int startIndex; startIndex = MyDataGrid.CurrentPageIndex * MyDataGrid.PageSize; MyDataGrid.CurrentPageIndex = e.NewPageIndex; BindGrid (); ShowStats ();} # region Web Form Designer generated codeoverride protected void OnInit (EventArgs e) {//// Codegen: This call is necessary for the ASP.NET Web Form Designer. //InitializeComponent ();Base.onit (E ); }///

/// Designer Supports the required method - Do not use the code editor to modify the /// this method. /// private () {this.load = new system.eventhandler (this.page_load);} # endregion}} ------------- Mr. Meng Xian

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

New Post(0)