void GridChanged(object sender, System.EventArgs e)
 {
    
       // Set CurrentPageIndex to the page the user clicked.
       DataGrid1.CurrentPageIndex = e.NewPageIndex;
    
       // Rebind the data.
       DataGrid1.DataBind();
    
    }

解决方案 »

  1.   


    void GridChanged(object sender, System.EventArgs e)
     {
        
           // Set CurrentPageIndex to the page the user clicked.
           DataGrid1.CurrentPageIndex = e.NewPageIndex;
          this.DataGrid1.DataSource=....;       // Rebind the data.
           DataGrid1.DataBind();
        
        }
      

  2.   

    谢谢回复,可是不行!出错信息:
    编译器错误信息: CS0117: “System.EventArgs”并不包含对“NewPageIndex”的定义源错误: 行 34:     
    行 35:        // Set CurrentPageIndex to the page the user clicked.
    行 36:        DataGrid1.CurrentPageIndex = e.NewPageIndex;
    行 37:     
    行 38:        // Rebind the data
     
    请继续讨论。
      

  3.   

    void GridChanged(Object sender, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
        {
            DataGrid1.CurrentPageIndex = e.NewPageIndex;
            DataGrid1.DataSource = products.Getguestview(Session["code"].ToString());
             DataGrid1.DataBind();
        }
      

  4.   

    void GridChanged(object sender,System.Web.UI.WebControls.DataGridPageChangedEventArgs e) {
        
           // Set CurrentPageIndex to the page the user clicked.
           DataGrid1.CurrentPageIndex = e.NewPageIndex;
          this.DataGrid1.DataSource=....;       // Rebind the data.
           DataGrid1.DataBind();
        
        }
      

  5.   

    加上datasource还是不行,如下:
    <script runat="server">
        
        jlzx.equipDB products = new jlzx.equipDB();
        
        void Page_Load(Object sender, EventArgs e) {
        
             if(!IsPostBack)
             {
                    
        
             // Databind and display the list of favorite product items
             if(Session["kind"].ToString()=="guest")
             {
             DataGrid1.DataSource = products.Getguestview(Session["code"].ToString());
             DataGrid1.DataBind();
             }
             else if(Session["kind"].ToString()=="user")
             {
             DataGrid1.DataSource = products.Getuserview(Session["code"].ToString());
             DataGrid1.DataBind();
             }
             else
             {
             DataGrid1.DataSource = products.Getadminview();
             DataGrid1.DataBind();
             }
           }
        }
         void GridChanged(Object sender, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
        {
        
           // Set CurrentPageIndex to the page the user clicked.
           DataGrid1.CurrentPageIndex = e.NewPageIndex;
        
           // Rebind the data.
           if(Session["kind"].ToString()=="guest")
             {
             DataGrid1.DataSource = products.Getguestview(Session["code"].ToString());
             DataGrid1.DataBind();
             }
             else if(Session["kind"].ToString()=="user")
             {
             DataGrid1.DataSource = products.Getuserview(Session["code"].ToString());
             DataGrid1.DataBind();
             }
             else
             {
             DataGrid1.DataSource = products.Getadminview();
             DataGrid1.DataBind();
             }
        
        }</script>
      

  6.   

    http://expert.csdn.net/Expert/topic/1549/1549222.xml?temp=.3974268
      

  7.   

    何不看看icyer的datagrid讨论,你需要重新指定数据源,页面刷新,数据源丢失
      

  8.   

    void GridChanged(Object sender, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
        {
        
           // Set CurrentPageIndex to the page the user clicked.
           DataGrid1.CurrentPageIndex = e.NewPageIndex;    jlzx.equipDB products = new jlzx.equipDB();
           // Rebind the data.
           if(Session["kind"].ToString()=="guest")
             {
             DataGrid1.DataSource = products.Getguestview(Session["code"].ToString());
             DataGrid1.DataBind();
             }
             else if(Session["kind"].ToString()=="user")
             {
             DataGrid1.DataSource = products.Getuserview(Session["code"].ToString());
             DataGrid1.DataBind();
             }
             else
             {
             DataGrid1.DataSource = products.Getadminview();
             DataGrid1.DataBind();
             }
        
        }
      

  9.   

    谢谢smiletosky(仰笑九天) equipdb.vsusing System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    namespace jlzx {
      
         
        public class equipDB : System.Web.UI.UserControl{        public DataView Getguestview(string code) 
            {            // Create Instance of Connection and Command Object
                SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["admin"]);
                SqlCommand myCommand = new SqlCommand("dt_retrunguest", myConnection);            // Mark the Command as a SPROC
                myCommand.CommandType = CommandType.StoredProcedure;
                           
                SqlParameter param = new SqlParameter("@code",SqlDbType.Char,2);
                param.Value = code;
                myCommand.Parameters.Add( param ); 
                
                // Execute the command
                SqlDataAdapter sda = new SqlDataAdapter();
    sda.SelectCommand = myCommand;
    if (myConnection.State==ConnectionState.Closed)
    myConnection.Open();
    DataSet ds=new DataSet();
    sda.Fill(ds,"tb1");
    myConnection.Close();
                DataView result = ds.Tables["tb1"].DefaultView;            // Return the dataview result
                return result;
            }
      

  10.   

    void GridChanged(Object sender, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)add: jlzx.equipDB products = new jlzx.equipDB();
      

  11.   

    回答pengweihua(pwh),加上jlzx.equipDB products = new jlzx.equipDB();也不行,这里是否不需要重新制定数据原。
      

  12.   

    OnPageIndexChange 改為 :OnPageIndexChanged
      

  13.   

    OnPageIndexChange 改為 :OnPageIndexChanged
    你少個"d"啊
      

  14.   

    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    DataGrid1.CurrentPageIndex = e.NewPageIndex;
    DataGrid1.DataBind();
    }
      

  15.   

    对不起,刚才离开了一会,又试了一下,OnPageIndexChange改為OnPageIndexChanged还是不行。我查了资料,asp.net高级编程里关于分页纸讲了一点,不详细。谁有着方面的书,推荐一下。多谢。
      

  16.   

    <script language ="C#" runat="server">
    你只試一下,如果還是不能,沒辦法!!
      

  17.   

    谢谢 pengweihua(pwh),我正在google搜索这方面文章,希望以后继续得到你的帮助。
      

  18.   

    <%@ outputcache duration="3600" varybyparam="None" %>
    都是这句代码惹得祸,我删除掉它后就一切正常,有水能告诉我它的确切含义?学习中。等待。
      

  19.   

    outputcache是页面缓存,它最好用于数据不是常更新的页面.
      

  20.   

    以后的分页一点就回到第一页了是因为你页面重载时又重新装载了datagrid,你应该在每次
    重载页面时都重载数据绑定,然后在分页绑定,也就是说把第一个if,else去掉。
      

  21.   

    问题终于解决了,把viewstate设为true,一切正常。谢谢各位的回复,散分。