在index.aspx里:
DataGrid1.CurrentPageIndex = (int)Request["page"];
DataGrid1.DataSource = ...;
DataGrid1.DataBind();

解决方案 »

  1.   

    private void Page_Load(object sender, System.EventArgs e)
    {

    if ( ! this.IsPostBack ) 
    {
        

    SetModel();
                                this.Bind();



    }
    } private void SetModel()
    {

    cPage="1";
    if(Request.Params["Page"]!=null)
    {
    cPage=Request.Params["Page"];
    DataGrid1.CurrentPageIndex=int.Parse(cPage)-1;
    }
    }
    private void Bind()
    {
    ......    this.DataGrid1.DataSource = ds.Tables[0].DefaultView;
    this.DataGrid1.DataBind();
    Pagination();

    }
    private void Pagination()
    {

    PageInfo.Text="页次:"+(DataGrid1.CurrentPageIndex+1)+"/"+DataGrid1.PageCount+" 每页"+DataGrid1.PageSize+"个主题 ";
    JumpTo.Text="" + (DataGrid1.CurrentPageIndex+1); if (DataGrid1.CurrentPageIndex == 0)
    {
    PageLink.Text="[首页] [上一页] ";
    }
    else
    {
    PageLink.Text="[<a href='Pubdoclist.aspx?id=0&Page=1'>首页</a>] [<a href='Pubdoclist.aspx?id=0&Page="+(DataGrid1.CurrentPageIndex)+"'>上一页</a>] ";
    }
    if (DataGrid1.CurrentPageIndex == DataGrid1.PageCount-1)
    { PageLink.Text=PageLink.Text+"[下一页] [尾页] ";
    }
    else
    {
    PageLink.Text=PageLink.Text+"[<a href='Pubdoclist.aspx?id=0&Page="+(DataGrid1.CurrentPageIndex+2)+"'>下一页</a>] [<a href='Pubdoclist.aspx?id=0&Page="+DataGrid1.PageCount+"'>尾页</a>] ";
    }
    }
      

  2.   

    以下是我的Page_load。我用你上面的方法不成功。可否帮助~谢谢。高定马上结贴。
    private void Page_Load(object sender, System.EventArgs e)
    {
    string Name = Request.QueryString["Name"];
    //Name = Server.UrlEncode(Name);
    Name = Server.HtmlEncode (Name);
    //创建连接字符串
    string strConnection = "user id=sa;password=sqlgoodboy;";
    strConnection += "initial catalog=PrimordialMusic;data source=127.0.0.1;";
    strConnection += "Connect Timeout=30";
    //创建查询字符串
    string strSQL = "SELECT * FROM \"Music\" where title  like '%" + Name + "%'";
    //string strSQL = "select * from singers join songs on singers.singer_id=songs.singer_id join album on songs.album_id=album.album_id where song_name like '%张%' or album_name like '%张%' or  singer_name like '%张%'";
    SqlConnection objConnection = new SqlConnection(strConnection);
    SqlDataAdapter objAdapter = new SqlDataAdapter(strSQL,objConnection);
    DataSet objDataSet = new DataSet();
    objAdapter.Fill(objDataSet,"singers");
    DataView objDataView = new DataView(objDataSet.Tables["singers"]);
    dgNameList.DataSource = objDataView;
    dgNameList.DataBind();
    }
      

  3.   

    高定乐。谢谢。。另外一个问题。DataGrid本身的分页是怎么样的?可一再url中判断么?
      

  4.   

    刚来。祝贺了。
    其实datgrid本身的分页是非常简单的,但也扩展性比较差,有时还会出错,推荐使用你这种或http://www.csdn.net/Develop/Read_Article.asp?Id=16055里面的分页控件。
      

  5.   

    回 boyyao(迷失在网络)短信cPage:公共变量,用于显示页次数的变量
    PageInfo:是页信息,如PageInfo.Text="页次:"+(dgfblist.CurrentPageIndex+1)+"/"+dgfblist.PageCount+" 每页"+dgfblist.PageSize+"个主题 ";
    JumpTo:是一个textbox,用于输入跳转的页次。
    PageLink:是一个label,如PageLink.Text="[首页] [上一页] ";PageLink.Text=PageLink.Text+"[下一页] [尾页] ";
      

  6.   

    datagrid自身的分页机制是每翻页一次dataset重新邦定数据库一次,效率较差。具体你可以参考
    ms-help://MS.VSCC/MS.MSDNVS.2052/Vbcon/html/vbwlkWalkthroughDisplayingDataInListBoxesOnWebFormsPage.htm