?
Solved

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

Posted on 2006-04-10
4
Medium Priority
?
225 Views
Last Modified: 2008-02-01
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!
0
Comment
Question by:RSSIAdmin
  • 3
4 Comments
 
LVL 10

Accepted Solution

by:
SystemExpert earned 2000 total points
ID: 16416760
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
 

Author Comment

by:RSSIAdmin
ID: 16419129
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
 

Author Comment

by:RSSIAdmin
ID: 16426204
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
 

Author Comment

by:RSSIAdmin
ID: 16435329
DataBind() call before and after running the boiler plate Excel routine did the trick.

Thanks for the input

RSSIAdmin
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question