473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Export Data from Datagrid to Excel

40
hi,

I have a dataTable in Session.On the click of a button in a Modal Dialog window I need to export this dataTable to Excel sheet.How could i do this...??
i tried using a window.open('Excel.aspx','','','') in the onclick of the button And wrote the code for export in the page load of Excel.aspx .But my session gets cleared.There are no datas in the dataTable.

i dont want to use query string...

Thanks in Advance,
Blacky
Mar 4 '09 #1
11 5224
Blacky
40
hi,

I have a dataTable in Session.On the click of a button in a Modal Dialog window I need to export this dataTable to Excel sheet.How could i do this...??
i tried using a window.open('Excel.aspx','','','') in the onclick of the button And wrote the code for export in the page load of Excel.aspx .But my session gets cleared.There are no datas in the dataTable.

i dont want to use query string...

Thanks in Advance,
Blacky
Mar 4 '09 #2
Frinavale
9,735 Expert Mod 8TB
Look into where and why your Session is getting cleared.
Mar 5 '09 #3
I am doing about the same thing with a gridview and found the "dialogArguments" property to be useful as in:

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. /* file popuptext.htm */
  3. function fnGetInfo()
  4. {
  5.   var sData = dialogArguments;
  6.   ta4details.innerText = sData;
  7.   ta4details.style.height = document.documentElement.clientHeight;
  8.   ta4details.style.width = "100%";
  9. }
  10. </scipt>
  11. ..
  12. <body onload="fnGetInfo();" ..
  13.  
I call it from my aspx page as follows:
Expand|Select|Wrap|Line Numbers
  1.    function LaunchGVRowCol(row, col) {
  2.         var ThisText = gridview1.rows[row].cells[col].title
  3.         showModelessDialog("popuptext.htm", ThisText, "dialogWidth:400px; dialogHeight:300px")
  4.     }
  5.  
My C# page stores the info to display in "title" which is the tooltip and creates the OnClick attribute
Expand|Select|Wrap|Line Numbers
  1.                     e.Row.Cells[desField].Attributes.Add("onclick", "return LaunchGVRowCol(" + e.Row.RowIndex + "," + nField.ToString() + ")");
  2.  
  3.  
HTH
Mar 5 '09 #4
Plater
7,872 Expert 4TB
In IE you can right-click the table and chose to export the data.

I on the other hand usually format my data as a CSV and allow the user to download/open it. Which normally would put it in Excel
Mar 9 '09 #5
Blacky
40
Can you give me the code snippet..?? i want to export data from a grid in popup window to excel.. this is my requirement.

thanks in advance,
Blacky
Mar 11 '09 #6
Blacky
40
Can you please tell me export from datagrid to excel.on click of a button in a modal dialog window
Mar 11 '09 #7
Plater
7,872 Expert 4TB
Have a page say "DownloadData.aspx" (or whatever) and pass it paramaters (querystring, post, session, whatever)
In that page build your data from the paramaters into a CSV, then change the response type to like "text/csv" and send the data down the response stream.
Mar 11 '09 #8
Frinavale
9,735 Expert Mod 8TB
Here's the thing, the most common solution to exporting data as an Excel file requires you to implement an ASPX page that returns an Excel file instead of HTML. The headers, mime types and content are configured to indicate to the browser that an Excel file is being sent to it instead of HTML and therefore the browser opens the "save file as" dialogue.

So once you have implemented the page that returns the Excel file, you need to configure your button to open this page....the Excel file will be sent to the browser and the user will be presented with a "save file" dialogue.
Mar 11 '09 #9
Blacky
40
the excel file is been generated and it is in temp. The problem is since i export the datagrid data to excel in a button click of a modal dialog window. I am not getting a popup to open a excel file or save it....

Since i need to maintain the datagrid items in the modal dialog, i have used
<base target="_self" /> in my html page.

This line of code does not make a popup for opening the excel...
anyways about how to handle it...??
Mar 12 '09 #10
Frinavale
9,735 Expert Mod 8TB
I'm wondering if an iFrame will help you.
Place an iFrame on the page, when the user clicks the "download Excel version" button have the iFrame load the ASPX page that returns the excel file. This should pop up the "Save As" dialogue.
Mar 12 '09 #11
wat r u using?
if u r binding the datagrid to a datatable or a dataset
use this
Expand|Select|Wrap|Line Numbers
  1. public static void WriteExcel(DataTable dt_Excel)
  2.         {
  3.             StringBuilder swColSb = new StringBuilder();
  4.             using (StreamWriter sw2Excel = File.CreateText(FileName.xls))
  5.             {
  6.                 //get the Columns of the DataTable in the 1st Line
  7.                 for (int i = 0; i < dt_Excel.Columns.Count; i++)
  8.                 {
  9.                     swColSb.Append(dt_Excel.Columns[i].ColumnName + "\t");
  10.                 }
  11.                 sw2Excel.WriteLine(swColSb.ToString());
  12.                 //Fill The Rows To the Excel File
  13.                 for (int i = 0; i < dt_Excel.Rows.Count; i++)
  14.                 {
  15.                     StringBuilder swRowSb = new StringBuilder();
  16.                     for (int k = 0; k < dt_Excel.Columns.Count; k++)
  17.                     {
  18.                         swRowSb.Append(dt_Excel.Rows[i][k].ToString() + "\t");
  19.                     }
  20.                     sw2Excel.WriteLine(swRowSb.ToString());
  21.                 }
  22.             }
  23.         }
  24.  
  25.  
and cal the function
Expand|Select|Wrap|Line Numbers
  1. WriteExcel((System.Data.DataTable)Datagrid.DataSource);

have fun


regards,
narz1986
Mar 30 '09 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: sunilkumar Reddy via DotNetMonster.com | last post by:
hai all first we can take binded grid Export to excel data from ultrawebgrid (or) datagrid rows, Each row data Expoting to one worksheet in excel workbook, like as grid row1 data contain sheet1...
6
by: Eric | last post by:
Dear All, I want to export datagrid content to a Excel file, the code just like below: Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" Me.EnableViewState = False Dim...
2
by: Bidarkota | last post by:
Hi, I have a DataGrid in which there are some images and Data are displayed and in the webform.asp page i am using some stylesheets. when i export the datagrid all the images are also exported...
0
by: sunilkumar Reddy via DotNetMonster.com | last post by:
hai all first we have taken binded grid Export to excel data from ultrawebgrid (or) datagrid rows, Each row data Expoting to one worksheet in excel workbook, like as grid row1 data contain...
6
by: Sridhar | last post by:
Hi, I have to export data inside the datagrid into an excel worksheet. I have to do this on button click event. I am trying to do like this. First get the DataTable from the datagrid and...
4
by: Frank | last post by:
Hello All, I ham using VS.NET 2003. Have followed instructions from http://gridviewguy.com/ArticleDetails.aspx?articleID=26 along with several other articles to no avail. I am pulling my hair...
7
by: mattmerc | last post by:
Hi all, We have all seen lot of method for exporting datagrids to Excel. I have a slightly different need. I think it should be easy to accomplish but I am not sure how. I would like when a user...
4
by: amitmnagarwal | last post by:
I have a page where i export to excel the content of Page 1 following code is written on page 2 to generate the excel Response.Buffer = True Response.ContentType = "application/vnd.ms-excel"...
19
by: cj2 | last post by:
#1 Is there a quick way to export a datatable to an excel file? Or delimited file? #2 Where is the appropriate Microsoft monitored group to ask about writing reports in SQL Reporting services...
5
by: Reggie | last post by:
Hi and TIA! I have an export procedure that exports my data from my datagrids to excel. The problem is that I lose leading zero's cause excel removes them and doesn't treat them as text. Is it...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.