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?
 
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
0
 
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!

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

Thanks for the input

RSSIAdmin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.