在Datagrid中属性中
我设置了绑定列,取消了运行时创建列,这样实现分页时,只会显示第一页,后面页不会显示。
这是为什么?怎样才能正常显示?请版主帮忙?急呀!!!!!!

解决方案 »

  1.   

    datagrid自带分页
    http://singlepine.cnblogs.com/articles/266538.html<asp:datagrid id="DataGrid1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
         PageSize="5" AllowPaging="True">    
        <Columns>
            <asp:TemplateColumn HeaderText="序号">
                <HeaderStyle Width="10px"></HeaderStyle>
                <ItemTemplate>
                    <INPUT id=radio onclick=fun_option(this) type=radio value='<%# DataBinder.Eval(Container.DataItem,"UserID") %>' name=radio>
                </ItemTemplate>
                <FooterTemplate>
                </FooterTemplate>
            </asp:TemplateColumn>
            <asp:TemplateColumn HeaderText="序号">
                <HeaderStyle Width="10px"></HeaderStyle>
                <FooterTemplate>
                </FooterTemplate>
            </asp:TemplateColumn>
        </Columns>
        <PagerStyle NextPageText="下一页" PrevPageText="上一页" HorizontalAlign="Right" ForeColor="DarkSlateBlue"
            BackColor="PaleGoldenrod" Mode="NumericPages"></PagerStyle>
    </asp:datagrid>
    private void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
                this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
                DataBind();
    }自定义分页
    http://singlepine.cnblogs.com/articles/281425.html
      

  2.   

    多谢小山哥
    以后还请多指点
    小山哥有没有QQ或Email以后如果有急事,好直接与你联系。
      

  3.   

    我的分页老是报告错误请小山哥看一下:“/Graduate”应用程序中的服务器错误。
    --------------------------------------------------------------------------------当 AllowPaging 设置为真并且选定的数据源不实现 ICollection 时,AllowCustomPaging 必须为真,并且 ID 为 DataGrid1 的 DataGrid 必须设置 VirtualItemCount。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Web.HttpException: 当 AllowPaging 设置为真并且选定的数据源不实现 ICollection 时,AllowCustomPaging 必须为真,并且 ID 为 DataGrid1 的 DataGrid 必须设置 VirtualItemCount。源错误: 
    行 45:  cmd.CommandText="Select * from elResInfo where resID='"+elResID+"'";
    行 46:  this.DataGrid1.DataSource=cmd.ExecuteReader();
    行 47:  this.DataGrid1.DataBind();
    行 48:  }
    行 49: 
     源文件: d:\wwwroot\graduate\mycontrols\elresource.ascx.cs    行: 47 堆栈跟踪: 
    [HttpException (0x80004005): 当 AllowPaging 设置为真并且选定的数据源不实现 ICollection 时,AllowCustomPaging 必须为真,并且 ID 为 DataGrid1 的 DataGrid 必须设置 VirtualItemCount。]
       System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource)
       System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
       System.Web.UI.WebControls.BaseDataList.DataBind()
       Graduate.MyControls.elResource.FillData() in d:\wwwroot\graduate\mycontrols\elresource.ascx.cs:47
       Graduate.MyControls.elResource.Page_Load(Object sender, EventArgs e) in d:\wwwroot\graduate\mycontrols\elresource.ascx.cs:29
       System.Web.UI.Control.OnLoad(EventArgs e)
       System.Web.UI.Control.LoadRecursive()
       System.Web.UI.Control.LoadRecursive()
       System.Web.UI.Control.LoadRecursive()
       System.Web.UI.Page.ProcessRequestMain() 
    --------------------------------------------------------------------------------
    版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573