473,379 Members | 1,187 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,379 software developers and data experts.

how to export a gridview to ms excell

hi i have a gridview which has 5 columns and atleast 100 rows.
i enabled sorting and paging. totally i have 10 rows in a page and hence i have 10 pages.

i need to export ths grid view to a ms-excell. i havent developed any codes since i'm a fresher in .net. i need detailed c# code for this task.

pls can any one help......

thanks...
Aug 28 '07 #1
2 1536
kenobewan
4,871 Expert 4TB
Here is an article that may help:
Exporting GridView to Excel
Aug 28 '07 #2
mzmishra
390 Expert 256MB
I did the same in the below way.You can do some other way too

1.create a button and add the below function to onclick event
function openXLSPage()
{

var controlName=document.getElementById("GridName");
//alert(controlName.value);
if(controlName.value=="GridName")
{
var str = escape("<BR>" + document.getElementById("GridName").outerHTML);
}
document.getElementById("xlsText").value = str;
xlsForm.submit();
}

2.put this form in your code
<form id="xlsForm" action="exporttoexcel.aspx" method="post" target="_blank">
<textarea id="xlsText" style="VISIBILITY: hidden" name="xlsText"></textarea>
</form>

3. create a file exporttoexcel.aspx and put the below code in aspx file
<%@ Page language="c#" Debug="true" CodeBehind="exportToExcel.aspx.cs" AutoEventWireup="false" Inherits="MorganStanley.ITRisk.ARCHI.UI.exportToEx cel" %>
<%@ Import Namespace="System.Drawing" %>
<%
Response.ContentType="application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState=false;
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Export to Excel</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<%
string DecodedString = Server.UrlDecode(Request.Form["xlsText"]);
Response.Write(DecodedString); %>
</body>
</HTML>
Aug 29 '07 #3

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

Similar topics

11
by: Not Me | last post by:
Hi, I'm trying to export from a gridview control, to an excel file using code intended for a datagrid control (it's all over the web, can post if requested) I get the error. Control...
0
by: Peter | last post by:
I experienced a bug, "Control GridView1 of type GridView myst be placed inside a form tag with runat=server". But I did so. I do not why, please advise. my code as below. Thanks. Peter <%@...
0
by: CSharpguy | last post by:
Ok, i got my gridview (sortable and non sorting) to export to excel. BUt now 3 of my gridviews I have a as:TemplateField which are links. So how can I hide those 3 columns when I export the...
3
by: =?Utf-8?B?bWFuaWthMDI=?= | last post by:
Hi, I have a GridView control in page called eventslisting which is inheriting from a MasterPage. The normal code to export to GridView does not work and gives me an error - "Control of type...
6
by: Sergio E. | last post by:
Hi, I'm looking for information about gridview's cell properties... I've the following case: one gridview with alternatirg row style and normalrowstyle, 3 o 4 custom styles that are applied to...
1
by: edwinparker | last post by:
Hi, I'm trying to convert a gridview to an excel report and have one small hang up. So far I've been able to create my gridview and export it to excel ok, but in my gridview I have an image. The...
2
nirmalsingh
by: nirmalsingh | last post by:
hai all, i need to export datagridview contents to a excell sheet including header. can anyone help me with sample code in c#. thanx in advance with Cheers Nirmal
0
by: =?Utf-8?B?U2hhbQ==?= | last post by:
Hai all, In my application, I need to Export webpage things into hard drive. I am using gridview, and i export all things(with the help of some sites) into excel except images. Please, Can...
3
by: ulai | last post by:
Thanks for your help. It really help to solve my work. But now i have a bigger problem : I had more than 65535 records in gridview divide by 10/pages. And when i tried to export the gridview in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.