如何在分页前把数据导入excel中?

maomao171314 2008-06-13 10:31:41
我现在用gridview从数据库里取出来了,由于数据太多,用了分页显示,但是把数据导入excel 中却出现了问题?
不分页 的时候没有问题....
该怎么实现?
...全文
80 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
S314324153 2008-06-20
  • 打赏
  • 举报
回复
数据源没分页的话,直接导数据源
数据源分页的话,只能用另一段sql导数据了
不赞成再隐藏一个datagrid之类的,如果数据量不大的话还好说,数据量大的时候就郁闷了
zlkingdom 2008-06-13
  • 打赏
  • 举报
回复
导的时候不分页就行
不管是用隐藏控件的方式还是将数据读入内存,都是可以的
ww3trhy 2008-06-13
  • 打赏
  • 举报
回复
BindDataGrid();

//隐藏的datagrid,用于打印
//清空
this.ExportPrint.DataSource = null;
this.ExportPrint.DataBind();
//查找数据
string sql_SelectAll = " select " + SearchContent + " from " + TableName + " " + WhereString + " " + OrderString + " desc ";
DataSet ds_SelectAll = p.DataSetSearch(strCon,sql_SelectAll);
DataTable dt_SelectAll = JoinData(ds_SelectAll);
if(dt_SelectAll != null && dt_SelectAll.Rows.Count > 0)
{
this.ExportPrint.DataSource = dt_SelectAll;
this.ExportPrint.DataBind();
}









ww3trhy 2008-06-13
  • 打赏
  • 举报
回复
页面上隐藏一个datagrid,在形成分页之后,同时执行一段查找全部数据的代码,将查找出的数据赋给这个datagrid,输出excell的时候用这个datagrid中的数据输出
ok/
qawszx 2008-06-13
  • 打赏
  • 举报
回复
如果数据源未分页,将数据源直接导到Excel
cpp2017 2008-06-13
  • 打赏
  • 举报
回复
导出的时候将它设为不分页.
xuebin_hu 2008-06-13
  • 打赏
  • 举报
回复
呵呵,这个问题好象以前有人问过,我答了.
代码帖上:

private void BindGrid()
{
GridView.DataSource = 数据源;
  GridView.DataBind()
}

protected void Button1_Click(object sender, ImageClickEventArgs e)
{
GridView.AllowPaging = false; //设置分页为false
GridView.AutoGenerateEditButton = false;
GridView.AutoGenerateDeleteButton = false;
BindGrid1(); //重新载入
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "gb2312";
Response.ContentType = "application/vnd.xls";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(" <meta http-equiv=Content-Type content=\"text/html; charset=GB2312\"> ");

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);


GridView.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
GridView.AllowPaging = true; //从新设置分页为true
}

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧