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!
RSSIAdminAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SystemExpertCommented:
Hi,

You can use SQL REPORTING SERVICES for export to excel,PDF ,..... and you can also  

or

private void ExportLinkButton_Click(object sender, System.EventArgs e)
{
  string strTitle = “put the grid title here”;
  new DataGridExcelExporter(this.YourGridName , this.Page).Export(strTitle);
}
where,

strTitle is the title of the DataGrid.
DataGridExcelExporter is the name of main class.
this.YourGridName is the DataGrid object.
this.Page is the current Page object.


or

 you can go for this link and find the solution

http://www.c-sharpcorner.com/Code/2003/Sept/ExportASPNetDataGridToExcel.asp

http://www.codersource.net/published/view/283/exporting_data_grid_to_excel.aspx

Thanks

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RSSIAdminAuthor Commented:
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!

RSSIAdminAuthor Commented:
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
RSSIAdminAuthor Commented:
DataBind() call before and after running the boiler plate Excel routine did the trick.

Thanks for the input

RSSIAdmin
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.