<asp:datagrid   id="DataGrid1"   runat="server"   CellSpacing="0"   CellPadding="2"     PagerStyle-HorizontalAlign="Right"   PageSize="3"   AllowPaging="True"     pagerstyle-nextpagetext="下一页"   pagerstyle-prevpagetext="上一页"   onpageindexchanged="changeage"></asp:datagrid>   
    
  然后在后台代码加入   
  sub   changepage(s   as   object,e   as   datagridpagechangedeventargs)   
  datagrid1.currentpageindex=e.newpageindex   
  end   sub

解决方案 »

  1.   

    给你一个自定义分页的例子
    .aspx
    <%@ Page language="c#" Codebehind="DataGridCustomPage.aspx.cs" AutoEventWireup="false" Inherits="CommonFunction.DataGridCustomPage" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>DataGridCustomPage</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="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <h2>DataGrid自定义分页的例子</h2>
    <asp:datagrid id="dgCustomPage" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 48px"
    runat="server" Width="376px" AutoGenerateColumns="False" CellPadding="4" BackColor="White"
    BorderWidth="1px" BorderStyle="None" BorderColor="#3366CC" Height="20px" AllowPaging="True"
    AllowCustomPaging="True" PageSize="5">
    <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
    <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
    <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
    <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
    <Columns>
    <asp:BoundColumn DataField="LastName" HeaderText="姓名"></asp:BoundColumn>
    <asp:BoundColumn DataField="FirstName" HeaderText="姓"></asp:BoundColumn>
    <asp:BoundColumn DataField="City" HeaderText="城市"></asp:BoundColumn>
    <asp:BoundColumn DataField="BirthDate" HeaderText="出生年月" DataFormatString="{0:D}"></asp:BoundColumn>
    </Columns>
    <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
    </asp:datagrid>
    </form>
    </body>
    </HTML>.CS
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Configuration;
    namespace CommonFunction
    {
    /// <summary>
    /// DataGridCustomPage 的摘要说明。
    /// </summary>
    public class DataGridCustomPage : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataGrid dgCustomPage;
    //定义全局变量用来保存每页的起始项索引
    int startIndex=0;
    private void Page_Load(object sender, System.EventArgs e)
    {
    //页面初试化时进行数据绑定
    if(!IsPostBack)
    DataGridDataBind();
    }
    private void DataGridDataBind()
    {
    //定义数据连接对象,其中数据库连接字符串是在Web.Config文件中定义的
    SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionSqlServer"].ToString());
    //创建数据适配器对象
    SqlDataAdapter da = new SqlDataAdapter("select LastName,FirstName,BirthDate,City from Employees",conn);
    //创建DataSet对象
    DataSet ds = new DataSet();
    try
    {
    //从指定的索引开始取PageSize条记录
    da.Fill(ds,startIndex,dgCustomPage.PageSize,"CurDataTable");
    //填充数据集
    da.Fill(ds,"AllDataTable");
    //设置DataGrid控件实际要显示的项数
    dgCustomPage.VirtualItemCount = ds.Tables["AllDataTable"].Rows.Count;
    //进行数据绑定
    dgCustomPage.DataSource = ds.Tables["CurDataTable"];
    dgCustomPage.DataBind();
    }
    catch(Exception error)
    {
    Response.Write(error.ToString());
    }
    }
    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.dgCustomPage.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgCustomPage_PageIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void dgCustomPage_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    //设置DataGrid当前页的索引值为用户选择的页的索引
    dgCustomPage.CurrentPageIndex = e.NewPageIndex;
    //取得当前页为止总共有多少条记录,以便在下一页就从该记录开始读取
    startIndex = dgCustomPage.PageSize * dgCustomPage.CurrentPageIndex;
    //重新绑定数据
    DataGridDataBind();
    }
    }
    }
      

  2.   

    第一.使用DataGrid的自带的分页控件
    第二.使用AspNetPager分页控件
    第三.自己写分页 参考http://www.cnblogs.com/sunnystar365/archive/2005/09/28/245665.html