ASP.NET技巧:DataGrid传统分页方式
- 编辑:admin -ASP.NET技巧:DataGrid传统分页方式
Type.GetType(System.String)); //myTable.Columns.Add(colItem1); //myTable.Columns.Add(colItem2); //myTable.Columns.Add(colItem3); //add row DataRow NewRow; for(int i=start;inumResults;i++) { if(ito) { NewRow = myTable.NewRow(); for(int k=0;kdataview.Table.Columns.Count;k++) { NewRow[k] = dataview.Table.Rows[i][k]; } myTable.Rows.Add(NewRow); } } myTable.AcceptChanges(); DataView resultDataview = new DataView(myTable); DataGrid1.DataSource = resultDataview; DataGrid1.DataBind(); /// summary /// 生成页导航条, System.EventArgs e) { // 在此处安排用户代码以初始化页面 if(!IsPostBack) { BindGrid(); } } private void BindGrid() { string connstring = Server=.;Database=NorthWind;User Id=sa;Password=;; string sql=Select * from Orders; SqlConnection conn = new SqlConnection(connstring); conn.Open(); DataSet ds = new DataSet(); SqlDataAdapter sqlAdapter = new SqlDataAdapter(sql,共 + pageCount.ToString() + 页; } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必须的,conn); sqlAdapter.Fill(ds,猛戳这里我要投稿 , DataGridPage.aspx 以下为引用的内容: %@ Page language=c# Codebehind=DataGridPage.aspx.cs AutoEventWireup=false Inherits=netCRM.DataGridPage % !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN HTML HEAD titleDataGridPage/title meta name=GENERATOR Content=Microsoft Visual Studio .NET 7.1 meta name=CODE_LANGUAGE Content=C# meta name=vs_defaultClientScript content=JavaScript meta name=vs_targetSchema content= /HEAD body MS_POSITIONING=GridLayout form id=Form1 method=post runat=server asp:datagrid id=DataGrid1 runat=server AlternatingItemStyle-BackColor=#eeeeee HeaderStyle-BackColor=#aaaadd Font-Size=8pt Font-Name=Verdana CellPadding=3 BorderWidth=1px BorderColor=Black PagerStyle-HorizontalAlign=Right PagerStyle-Mode=NumericPages PageSize=5 Font-Names=Verdana Width=100% AlternatingItemStyle BackColor=#EEEEEE/AlternatingItemStyle HeaderStyle BackColor=#AAAADD/HeaderStyle PagerStyle HorizontalAlign=Right Mode=NumericPages/PagerStyle /asp:datagrid /form TABLE cellSpacing=0 cellPadding=1 width=100% bgColor=#aaaadd border=0 TBODY TR TD TABLE cellSpacing=0 cellPadding=4 width=100% bgColor=#fef8e2 border=0 TBODY TR TD class=M noWrap align=centerasp:Literal id=Literal1 runat=server/asp:Literal/TD /TR TR TD class=C noWrap align=centerasp:Literal id=Literal2 runat=server/asp:Literal/TD /TR /TBODY /TABLE /TD /TR /TBODY /TABLE /body /HTML DataGridPage.aspx.cs 以下为引用的内容: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.SqlClient; 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 netCRM { /// summary /// DataGridPage 的摘要说明,Type.GetType(System.String)); //DataColumn colItem3 = new DataColumn(vendor,out a1); if (a10) { pageCount++; } if(currentPagepageCount || currentPage=0) { currentPage = 1; } if(currentPage==pageCount) { to = dataview.Count; } // Create one DataTable with one column. DataTable myTable = new DataTable(myTable); myTable = dataview.Table.Clone(); //DataColumn colItem1 = new DataColumn(name, 此分页方法与传统ASP分页方法相仿,users); DataView dataview = new DataView(); dataview = ds.Tables[0].DefaultView; DataGrid1.DataSource = ds.Tables[0].DefaultView; DataGrid1.DataBind(); string cPage; int pageSize = 10; int currentPage; int pageCount; int numResults = 0; if (Request.QueryString[page]==null) { cPage=1; } else { cPage=Request.QueryString[page].ToString(); } try { currentPage = Int32.Parse(cPage); } catch { currentPage = 1; } numResults = 0; int start = (int)((currentPage - 1) * pageSize); int to = (int)(currentPage * pageSize); if (start = 0) start = 0; numResults = dataview.Count; int a1=0; pageCount = Math.DivRem(numResults, /// /summary public class DataGridPage : System.Web.UI.Page { protected System.Web.UI.WebControls.Literal Literal1; protected System.Web.UI.WebControls.Literal Literal2; protected System.Web.UI.WebControls.DataGrid DataGrid1; private void Page_Load(object sender, /// /summary private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } } 有好的文章但愿站长之家辅佐分享推广, // InitializeComponent(); base.OnInit(e); } /// summary /// 设计器支持所需的要领 - 不要使用代码编辑器修改 /// 此要领的内容,www.hnbwcw.com, /// /summary string strNav = ; int endpage; if (currentPage1) { strNav += a href='?page=+ (currentPage-1).ToString() +'上一页/a ; } if (currentPage11) { strNav += a href='http://www.chinaz.com/program/2007/0806/?page=1'1/a ...; } if(pageCountcurrentPage+10) { endpage = currentPage+10; } else { endpage = pageCount; } for (int i=currentPage-10;iendpage+1;i++) { if(i=1) { if (i==currentPage) { strNav +=font color=#990000strong+ i.ToString() +/strong/font ; } else { strNav += a href='?page=+ i.ToString() +'+ i.ToString() +/a ; } } } if((currentPage+10)pageCount) { strNav += ... a href='?page=+ pageCount.ToString() +'+ pageCount.ToString() +/a; } if(currentPagepageCount) { strNav += a href='?page=+ (currentPage+1).ToString() +'下一页/a ; } Literal1.Text = strNav; Literal2.Text = 共 + numResults.ToString() + 条供给信息,53d,Type.GetType(System.String)); //DataColumn colItem2 = new DataColumn(types,www.aepnet.com,当前显示第 + (start+1).ToString() + - + to.ToString() + 条。
pageSize,。