我们的程序里面用的是DataGrid的自动分页的功能
AllowPaging=true AllowCustomPaging=false
单独查看这个页面可以实现分页的功能
但是运行程序跳转到有分页的页面时就有问题
问题是要把AllowCustomPaging=true,但改成AllowCustomPaging=true后,分页的功能又不能实现,不知道是怎么回事
有知道的请教一下我们

解决方案 »

  1.   

    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
    this.DataGrid1.SelectedIndex = -1;
    sql_conect();
    }
      

  2.   

    你的DataSource类型是不是DataView呢!?如果是的话就不会出现这个问题!
    如果你的绑定的是SqlDataReader的话,就不行。。特别是在设置了分页功能!
      

  3.   

    错误是
    当 AllowPaging 设置为真并且选定的数据源不实现 ICollection 时,AllowCustomPaging 必须为真,并且 ID 为 DataGrid1 的 DataGrid 必须设置 VirtualItemCount。
      

  4.   

    分页使您可以按页段显示 DataGrid 控件的内容。页上的项数由 PageSize 属性确定。如果没有为 PageSize 属性指定任何值,则 DataGrid 将在一页上显示 10 项。通常,在每次 DataGrid 控件移到不同页时都将加载包含 DataGrid 控件中每一行的数据源。当数据源很大时这会占用大量资源。自定义分页使您可以只加载显示单页所需的数据段。若要启用自定义分页,请将 AllowPaging 和 AllowCustomPaging 属性都设置为 true。接下来,提供用来处理 PageIndexChanged 事件的代码。PageIndexChanged 事件处理程序的典型逻辑是首先将 CurrentPageIndex 属性设置为您要显示的页的索引。注意 
    事件处理程序接收 DataGridPageChangedEventArgs 对象作为参数。可以使用该参数的 NewPageIndex 属性来确定用户从 DataGrid 控件的页选择元素中所选择的页的索引。
     接下来,创建包含要在单页显示的数据的数据源,然后使用 DataBind 方法将数据绑定到 DataGrid 控件。注意 
    因为只加载一个数据段,所以您必须将 VirtualItemCount 属性设置为 DataGrid 控件中各项的总数。这使得该控件可以确定显示 DataGrid 控件中每一项所需的总页数。只要确定了 DataGrid 控件中的总项数,通常就可以用编程的方式设置此属性。
     在通过将 AllowCustomPaging 属性设置为 false 来启用分页后,DataGrid 控件假设数据源包含所有要显示的项。DataGrid 控件根据 CurrentPageIndex 属性指定的页索引以及 PageSize 属性指定的页上项的数目来计算显示的页上各项的索引。当 AllowCustomPaging 属性设置为 true 时,DataGrid 控件假设数据源只包含由 VirtualItemCount 属性确定的项。所有项(项数最多可达由 PageSize 属性指定的数目)都将显示出来。
    ===========以上完全摘录自msdn,示例代码自己看看======================
    试着先自己找资料解决
    ==== 
    ~~~~ 我的Blog:http://blog.csdn.net/quou2002 
      

  5.   

    应该是DataSource设置的问题,我昨天也遇到咯
    SqlConnection con=DB.createConnection();
    SqlDataAdapter sdr=new SqlDataAdapter();
    sdr.SelectCommand=new SqlCommand("select * from sharetable",con);
    DataSet dt=new DataSet();
    sdr.Fill(dt,"sharetable");
    this.DataGrid1.DataKeyField="id";
    this.DataGrid1.DataSource=dt.Tables["sharetable"];
    this.DataGrid1.DataBind();
    这样绑定就应该行咯
      

  6.   

    对照以下代码看看吧:
    <%@ Page Language="VB" AutoEventWireup="True" Debug="true"%>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SQLClient" %>
    <script runat="server">
          Dim MyConnection as SQLConnection
          Dim MyCommand As SQLDataAdapter      Sub Page_Load(sender As Object, e As EventArgs) 
      MyConnection = New SqlConnection("server=localhost;Initial Catalog=pubs;uid=sa;pwd=")
              If Not IsPostBack Then 
                 BindGrid()
              End If
          End Sub      Sub BindGrid() 
          Dim MyCommand As SQLDataAdapter = new SQLDataAdapter("SELECT * FROM authors", MyConnection)
              Dim DS As DataSet = new DataSet()
              MyCommand.Fill(DS,"min") 
              MyDataGrid.DataSource = DS.Tables("min").DefaultView
              MyDataGrid.DataBind()
          End Sub
    </script>
    <form runat="server">
        <asp:DataGrid id="MyDataGrid" 
               runat="server"
       AutoGenerateColumns="true"
       Width="200">
             <HeaderStyle BackColor="Navy" 
                          ForeColor="White" 
                          Font-Bold="True" 
      HorizontalAlign="Center"/>
             <PagerStyle Mode="NextPrev"
                         HorizontalAlign="Right" 
     NextPageText="下一页"
                         PrevPageText="上一页"/>
          </asp:DataGrid>
    </form>
      

  7.   

    自定义分页
    http://dotnet.aspx.cc/ShowDetail.aspx?id=108B1516-53CE-4357-B061-17295AF9689F
      

  8.   

    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    DataGrid1.CurrentPageIndex=e.NewPageIndex;
    BindGrid();
    }
    这里设置没有?