Link to home
Start Free TrialLog in
Avatar of RSSIAdmin
RSSIAdmin

asked on

I'm trying to export a girdview to excel and some how must turn sorting and paging off .

I've seen this link out there but I using std NET 2.0 C# sqldatasource and have no bind method like that show in
this nice writeup:
http://geekswithblogs.net/azamsharp/archive/2006/01/09/65368.aspx


The GridView dump to excel works fine if I add a button to  turn page and sort off first!

But I need something that will turn page and sort off automatically before I go  into the boiler plate excel routine and then turn page and sort back on after the excel dump is done. Again I cannot turn
paging  and sorting off like this
        GridView1.AllowPaging = false;
        BindData(); ?

since I am binding Grdidview using the NET 2.0 std sqlDataSource SELECTCommand SELECT   etc stuff and don't have the a BindData() method to the best of my knowlege.

Help!
ASKER CERTIFIED SOLUTION
Avatar of SystemExpert
SystemExpert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RSSIAdmin
RSSIAdmin

ASKER

SystemExpert.... Thanks for the quick and  excellent response!

Yes the following code http://geekswithblogs.net/azamsharp/archive/2006/01/09/65368.aspx is about want I am currently using and it works great!

But only if paging and sorting or both turn off ??   I try doing the switch paging and off  with code below and it does not work  and I don't have I don't have a
GridView1.DataSource = ds;
        GridView1.DataBind();  method since an using the NET 2.0 boiler plate sqlDatasource  selectcommand in aspx page setup?


I tried the following to turn paging and sorting "off " before excel dump render code and then turn then both  "on"
again excel render control but I wind-up with an exception error!  If I add a button to manually turn paging and sorting
off before clicking the excel print button yes it works but I need to do the same automatically!

HERE IS MY CODE ( at least what I tried!)

mygridview.paging = false;  <----- my addition
mygridview.sorting = false;  <------  ...

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");

Response.Charset = "";

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

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

myDataGrid.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

mygridview.paging = false;  <------- my addition
mygridview.sorting = false;  <------- .......



Response.End();


Help!

SystemExpert.... Thanks for the quick and  excellent response!

Yes the following code http://geekswithblogs.net/azamsharp/archive/2006/01/09/65368.aspx is about want I am currently using and it works great!

But only if paging and sorting or both turned off ??  I added a button to manually turn paging and sorting
off  before clicking the excel print button and yes it works!  But I need to do the same automatically!


I tried the following to turn paging and sorting "off " before excel dump render code and then turn then both  "on"
again excel render control but I wind-up with an exception error!

HERE IS MY CODE ( at least what I tried!)

mygridview.paging = false;  <----- my addition
mygridview.sorting = false;  <------  my addition
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");

Response.Charset = "";

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

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

myDataGrid.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());
mygridview.paging = false;  <------- my addition
mygridview.sorting = false;  <------- my addition
DataBind() call before and after running the boiler plate Excel routine did the trick.

Thanks for the input

RSSIAdmin