VS2005,关于GridView分页与到处Excel的问题
我是采用GridView的自动分页方式,分页正常,有2个问题:1.当我要到处到Excel文件是始终只能导出当前页,而不能导出我查询的所有数据,我设置GridView.AllowPaging="false"也一样.怎样解决这个导出全部数据的问题?
2.当GridView的行数少于分页数时,GridView就没有分页的效果,这不太好看,怎样让它即使只有一行记录也有分页的效果? --------------------编程问答-------------------- 不知道了,帮顶. --------------------编程问答-------------------- 自己顶一下... --------------------编程问答-------------------- 把你的导出的代码贴出来,这样子才好解决! --------------------编程问答-------------------- GridView导入到Excel中,当有分页是就有乱码而且只能导处当前页,没有分页是一切正常
代码如下:
protected void Button2_Click(object sender, EventArgs e)
{
ToExcel(myGridView, "huadan");
}
public static void ToExcel(System.Web.UI.Control ctl, string FileName)
{
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName + ".xls");
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for
}
--------------------编程问答-------------------- 学习一下 --------------------编程问答-------------------- up......关注中......我也遇到同样的问题...一直没有得到解决 --------------------编程问答-------------------- 导出前GridView.PageSize=导出的总记数;即可,我的所有项目都是这样用,效果还好! --------------------编程问答-------------------- --------------------编程问答-------------------- protected void Button2_Click(object sender, EventArgs e)
{
this.GridView1.AllowPaging = false;
this.GridView1.AllowSorting = false;
Bind();
到处函数();//这函数里面this.GridView1.AllowPaging属性不给
this.GridView1.AllowPaging = true;
this.GridView1.AllowSorting = true;
Bind();
}
补充:.NET技术 , ASP.NET