开发者

Problem when export from grid to excel file

i want to export all pages of GridView to excel . but the problem is when i set allowpaging to false then bind data again to grid.开发者_StackOverflow the grid become empty but the headers are still existing . what's the problem ?

gv.AllowPaging = false;
gv.DataBind();

Problem when export from grid to excel file

but when i use 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. 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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜