问题如下:  datagrid 现在可以显示数据,也可以分页Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
      
        Me.DataGrid1.CurrentPageIndex = e.NewPageIndex 
        Me.DataGrid1.DataBind()我在同一个页面中做了一个查询,也在同一个datagrid中显示数据,但是这个时候,查询就不能用了,请问这是怎么回事?请指教

解决方案 »

  1.   

    按了查询按钮出现
    当 AllowPaging 设置为真并且选定的数据源不实现 ICollection 时,AllowCustomPaging 必须为真,并且 ID 为 DataGrid1 的 DataGrid 必须设置 VirtualItemCount。 
    错误提示,这个提示看不懂
      

  2.   

    就是你的数据源必须为dateset 才可以自动分页!
      

  3.   

    查询得到的数据源是什么?DateReader?
      

  4.   

    说你的AllowCustomPaging 没设定为真,VirtualItemCount没有指定分页的页数吧?
    这些可以在属性生成器里设置的啊,我用过没遇上这样的问题。
      

  5.   

    应该是没有考虑到
    if (!Page.IsPostBack) 
    {}
    的问题把
      

  6.   

    是DateReader,这个不行吗,要用 dataset?
      

  7.   

    不查询之前都可以分页的,查询之后,就不行了,我试试dataset
      

  8.   

    楼主还是不要用grid的自动分页
    服务器压力太大
      

  9.   

    DateReader不可以的,因为DateReader提供向前的读机制,不存在内存中!
      

  10.   

    哦,知道了,刚刚学.net,很多东西不懂,以后还请多指教
    没关系我们只是一个小网站,况且我还在学习当中,先用datagrid自动分页,以后再学高级的
      

  11.   

    参考:
    http://anyqu.mblogger.cn/posts/6350.aspx
    有详细的说明!
      

  12.   

    你把viewstate禁用了吗?
    你的邦定语法怎么写的?
    参考我的:
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!IsPostBack)
    {
    BindData();
    Response.Write(DateTime.Now.ToString("yyyy-MM-dd"));
    }

    }
    private void BindData()
    {
    SqlConnection sqlcon  = new SqlConnection(Configuration.ConnectionString);
    SqlCommand sqlcom  =new SqlCommand();
    sqlcon.Open();
    sqlcom.Connection = sqlcon;
    sqlcom.CommandText = "select a.SubProjectID ,a.TSMainProID,FristCensorDate ,b.MainBulidUnit ,b.SubRegisterContent,"+
                                     " c.sjdwmc,c.kcdwmc,b.SubProjectName " +
                                     " from TS_ProState a  left join  TS_ProjectInformation b on a.SubProjectID = b.SubProjectID "+
                                     " left join TS_TSProjectInfo c on a.SubProjectID = c.dxgcbh "+
                     " where a.SubProjectID like '%"+TextKeyWords.Text.ToString()+"%' and  isnull(TSMainProID,'popopopo')!= 'popopopo'";
    SqlDataReader my = null;
    try
    {
    my = sqlcom.ExecuteReader();  
    projectinfo.DataSource = my;
    projectinfo.DataBind();

    }
    catch(Exception e)
    {
    throw(e);
    }
    finally
    {
    sqlcon.Close();
    my.Close();
    }
    }
    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.projectinfo.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.projectinfo_ItemCommand);
    this.projectinfo.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.projectinfo_ItemDataBound);
    this.projectinfo.SelectedIndexChanged += new System.EventHandler(this.projectinfo_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
     BindData(); }
    注意那个TextKeyWords.Text.ToString()为你的关键字输入的textbox值!
      

  13.   

    忘记写分页了:
    private void projectinfo_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    try
    {
    projectinfo.CurrentPageIndex =  e.NewPageIndex;
    BindData();
    }
    catch
    { } }
      

  14.   

    viewstate  没禁用,
     Dim my As New OleDbDataAdapter("SELECT T_BookInfo.Book_ID where " & Me.DropDownList1.SelectedValue & " like '%" & Me.TextBox1.Text & "%' order by T_BookInfo.Book_ID desc", conn)
            Dim ds As New DataSet
                   my.Fill(ds, "T_BookInfo")        Me.DataGrid1.DataSource = ds.Tables("T_BookInfo").DefaultView
            Me.DataGrid1.CurrentPageIndex = 0
            Me.DataGrid1.DataKeyField = "Book_ID"
            Me.DataGrid1.DataMember = "T_BookInfo"
            Me.DataGrid1.DataBind()
          
    分页
    Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged        Me.DataGrid1.CurrentPageIndex = e.NewPageIndex
      Me.DataGrid1.DataBind()
    SELECT语句太长,我删除了一写,我对C#不懂,不过我还是看一下,你说的那个传,怎么传,我不会
      

  15.   

    你写个专有的邦定函数, 函数带参数关键字,  
    Me.DataGrid1.CurrentPageIndex = e.NewPageIndex
     //你的邦定函数
    就可以了,我太不懂VB语法的!
      

  16.   

    就是你把BindData()方法写在你自己的邦定函数里面!
      

  17.   

    参考
    blog.csdn.net/zhzuo/archive/2004/10/28/156647.aspx