当把DataGrid的allowpaging设置为"true"时,DataGrid中的数据就无法倒入到excel中,提示错误:"类型“DataGridLinkButton”的控件“DataGrid1__ctl19__ctl1”必须放在具有 runat=server 的窗体标记内。"  DataGrid的allowpaging设置为"true"时,数据可以倒入到excel.
期待高手出手....

解决方案 »

  1.   

    要先取消分页,再导,附了相关代码,你参考一下:
    private void btExportExcel_Click(object sender, System.EventArgs e)
    {
    Response.ContentType = "application/vnd.ms-excel";
    Response.Charset="GB2312";    
    Response.AppendHeader("Content-Disposition","attachment;filename=UpdateDataLog.xls"); 
    Response.ContentEncoding=System.Text.Encoding.UTF7;  //设置输出流为简体中文
    this.EnableViewState = false;
    System.IO.StringWriter sw = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
    int nCur = this.dgViewLog.CurrentPageIndex;
    int nSize = this.dgViewLog.PageSize;

    this.dgViewLog.AllowPaging = false;
    this.BindGrid();

    // this.dgViewLog.Columns[0].Visible =false;
    // this.dgViewLog.Columns[5].Visible =false;
    // this.dgViewLog.Columns[6].Visible =false;
    // this.dgViewLog.Columns[7].Visible =false;
    // this.dgViewLog.Columns[8].Visible =false;
    this.dgViewLog.RenderControl(hw);
    // this.dgViewLog.Columns[0].Visible =true;
    // this.dgViewLog.Columns[5].Visible =true;
    // this.dgViewLog.Columns[6].Visible =true;
    // this.dgViewLog.Columns[7].Visible =true;
    // this.dgViewLog.Columns[8].Visible =true;

    //以下恢复分页
    this.dgViewLog.AllowPaging = true;
    this.dgViewLog.CurrentPageIndex = nCur;
    this.dgViewLog.PageSize = nSize;
    this.BindGrid();
    Response.Write(sw.ToString());
    Response.End(); }
      

  2.   

    DataGrid1.AllowPaging = false;
    //重新绑定//导出到excelDataGrid1.AllowPaging = ture;
    //再次重新绑定
      

  3.   

    谢谢上面各位的帮助。项目中要求分页显示,而且往EXCEL或WORD倒入的时候要求分页倒入,就是倒入的格式与DataGrid显示的格式是一样的。
      

  4.   

    楼主,这样不太可能吧.呵呵.在excel中可以实现点下一页就到另一页的效果吗?
      

  5.   

    excel没办法分页,你只能导excel的时候allowpaging=false;导入完毕之后allowpaging=true;