All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
使用Forms,Authentication实现用户注册、登录,(二)用户注册与登录_[Asp.Net教程]
delphi类中方法的使用技巧和实例
MySQL与ASP.NET配合更强大_.net资料_编程技术
delphi在文本文件中添加一行
Asp.Net,XML操作基类_[Asp.Net教程]
技巧:使用User,Control做HTML生成_[Asp.Net教程]
不需要mod_rewrite直接使用php实现伪静态化页面_[PHP教程]
解决无法显示javascript页面故障_JavaScript技术_编程技术
比较SQL,Server,2000,数据库中两个库的差异_[SQL,Server教程]
了解Hibernate的FlushMode.NEVER_.net资料_编程技术
Reading number is top 10 pictures
The terra-cotta warriors2
Wear bikinis cock
Discharge accidentally Actresses by the breast3
宝贝系列
Get girl by your hand
The money of more than 100 countries and regions3
Plump breasts1
浴室里的美女
再来随便发几张
29 the belle stars after bath figure5
Download software ranking
matrix2
The Bermuda triangle3
Boxer vs Yellow2
Unix video tutorial6
Desire a peach blossom
Tram sex maniac 2 (H) rar bag2
双旗镇刀客A
Dance with duck(male prostitution)
Sora aoi - one of more PK
Unix video tutorial11
delv published in(发表于) 2014/1/24 9:07:58 Edit(编辑)
ASP.NET技巧:DataGrid传统分页方式_[Asp.Net教程]

ASP.NET技巧:DataGrid传统分页方式_[Asp.Net教程]

ASP.NET技巧:DataGrid传统分页方式_[Asp.Net教程]

此分页方式与传统ASP分页方式相仿.


DataGridPage.aspx


<%@ Page language="c#" Codebehind="DataGridPage.aspx.cs" AutoEventWireup="false" Inherits="netCRM.DataGridPage" %>



DataGridPage







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%">













































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
{
///


/// DataGridPage 的摘要说明。
///

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, 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,conn);
sqlAdapter.Fill(ds,"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,pageSize,out a1);
if (a1>0)
{
pageCount++;
}
if(currentPage>pageCount || 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",Type.GetType("System.String"));
//DataColumn colItem2 = new DataColumn("types",Type.GetType("System.String"));
//DataColumn colItem3 = new DataColumn("vendor",Type.GetType("System.String"));
//myTable.Columns.Add(colItem1);
//myTable.Columns.Add(colItem2);
//myTable.Columns.Add(colItem3);
//add row
DataRow NewRow;
for(int i=start;i {
if(i {
NewRow = myTable.NewRow();
for(int k=0;k {
NewRow[k] = dataview.Table.Rows[i][k];
}
myTable.Rows.Add(NewRow);
}
}
myTable.AcceptChanges();
DataView resultDataview = new DataView(myTable);
DataGrid1.DataSource = resultDataview;
DataGrid1.DataBind();
///
/// 生成页导航条。
///

string strNav = "";
int endpage;
if (currentPage>1)
{
strNav += "上一页 ";
}
if (currentPage>11)
{
strNav += "1 ...";
}
if(pageCount>currentPage+10)
{
endpage = currentPage+10;
}
else
{
endpage = pageCount;
}
for (int i=currentPage-10;i {
if(i>=1)
{
if (i==currentPage)
{
strNav +=""+ i.ToString() +" ";
}
else
{
strNav += ""+ i.ToString() +" ";
}
}
}
if((currentPage+10) {
strNav += "... "+ pageCount.ToString() +"";
}
if(currentPage {
strNav += " 下一页 ";
}
Literal1.Text = strNav;
Literal2.Text = "共 "+ numResults.ToString() +" 条供应信息,当前显示第 "+
(start+1).ToString() +" - "+ to.ToString() +" 条,共 "+ pageCount.ToString() +" 页";
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}








添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.