[英]Problem when export from grid to excel file
i want to export all pages of GridView to excel . 我想将GridView的所有页面导出到excel。 but the problem is when i set allowpaging to false then bind data again to grid. 但是问题是当我将allowpaging设置为false然后将数据再次绑定到网格时。 the grid become empty but the headers are still existing . 网格变为空,但标题仍然存在。 what's the problem ? 有什么问题 ?
gv.AllowPaging = false;
gv.DataBind();
but when i use Linqtodatasource. 但是当我使用Linqtodatasource时。 it works fine . 它工作正常。
try setting the datasource of the grid to the datasource again before rebinding. 在重新绑定之前,请尝试再次将网格的数据源设置为数据源。 I think the LinqToSQL datasource works becuase its added to the page and is re-added automatically, I'm assuming you are setting the datasource manually so it needs to be set when rebinding. 我认为LinqToSQL数据源的工作原理是将其添加到页面并自动重新添加,我假设您是手动设置数据源,因此在重新绑定时需要设置它。 Well that usually works for me anyway 好吧,无论如何,这通常对我有用
eg: 例如:
private DataTable DataSource
{
get
{
string sessionKey = String.Format("DataSource_{0}", this.UniqueID);
if (Session[sessionKey] == null)
{
Session[sessionKey] = new DataTable();
}
return Session[sessionKey] as DataTable;
}
set
{
string sessionKey = String.Format("DataSource_{0}", this.UniqueID);
Session[sessionKey] = value;
}
}
private void ExportToExcel()
{
gv.AllowPaging = false;
gv.DataSource = this.DataSource;
gv.DataBind();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.