473,394 Members | 2,020 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,394 software developers and data experts.

Exporting data from (All columns in data grid EXCEPT THE 1st) to E

Hi,

I am exporting data from an EDITABLE DATA GRID EXCEL. But the 1st column
in data grid is Edit Column. I want to display all columns in Excel except
for the Edit column.

The following code which I am using allows exporting only from text data
from data grid & not from Edit columns which are link buttons. How to leave
this column while displaying data from data grid in Excel?

Code:
public void PerformExcelView()
{
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;

System.IO.StringWriter SW = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter HTW = new System.Web.UI.HtmlTextWriter(SW);
DataGrid1.RenderControl(HTW);
Response.Write(SW.ToString());
Response.End();
}

// From button click I am calling this function

private void btnExcel_Click(object sender, System.EventArgs e)
{
PerformExcelView();
}

Also, I tried to REMOVE theEDIT COLUMN on button click
.....DataGrid1.Columns.Remove(DataGrid1.Columns[0]);
& then calling the function PerfromExcelView() but I got the error:
"Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index ".

How to get over this problem?
Any help will be appreciated .

Thanks
--
pmud
Nov 19 '05 #1
2 2289
Check this out,
http://weblogs.asp.net/dneimke/archi.../27/63348.aspx

There are some comments by some people who have your problem, and a solution

--Michael

"pmud" <pm**@discussions.microsoft.com> wrote in message news:30**********************************@microsof t.com...
Hi,

I am exporting data from an EDITABLE DATA GRID EXCEL. But the 1st column
in data grid is Edit Column. I want to display all columns in Excel except
for the Edit column.

The following code which I am using allows exporting only from text data
from data grid & not from Edit columns which are link buttons. How to leave
this column while displaying data from data grid in Excel?

Code:
public void PerformExcelView()
{
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;

System.IO.StringWriter SW = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter HTW = new System.Web.UI.HtmlTextWriter(SW);
DataGrid1.RenderControl(HTW);
Response.Write(SW.ToString());
Response.End();
}

// From button click I am calling this function

private void btnExcel_Click(object sender, System.EventArgs e)
{
PerformExcelView();
}

Also, I tried to REMOVE theEDIT COLUMN on button click
....DataGrid1.Columns.Remove(DataGrid1.Columns[0]);
& then calling the function PerfromExcelView() but I got the error:
"Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index ".

How to get over this problem?
Any help will be appreciated .

Thanks
--
pmud

Nov 19 '05 #2
Thanks Raterus. This was helpful.

"Raterus" wrote:
Check this out,
http://weblogs.asp.net/dneimke/archi.../27/63348.aspx

There are some comments by some people who have your problem, and a solution

--Michael

"pmud" <pm**@discussions.microsoft.com> wrote in message news:30**********************************@microsof t.com...
Hi,

I am exporting data from an EDITABLE DATA GRID EXCEL. But the 1st column
in data grid is Edit Column. I want to display all columns in Excel except
for the Edit column.

The following code which I am using allows exporting only from text data
from data grid & not from Edit columns which are link buttons. How to leave
this column while displaying data from data grid in Excel?

Code:
public void PerformExcelView()
{
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;

System.IO.StringWriter SW = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter HTW = new System.Web.UI.HtmlTextWriter(SW);
DataGrid1.RenderControl(HTW);
Response.Write(SW.ToString());
Response.End();
}

// From button click I am calling this function

private void btnExcel_Click(object sender, System.EventArgs e)
{
PerformExcelView();
}

Also, I tried to REMOVE theEDIT COLUMN on button click
....DataGrid1.Columns.Remove(DataGrid1.Columns[0]);
& then calling the function PerfromExcelView() but I got the error:
"Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index ".

How to get over this problem?
Any help will be appreciated .

Thanks
--
pmud

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hutty | last post by:
I've looked around and have yet to find anything that would answer my question regarding formating a column in a datagrid. My grid looks like this as far as data" AMHQCON|51300.01|-3147 The...
3
by: pmud | last post by:
Hi, I have a web page (asp.net, code:c#). I havean html table with text boxes. Based on the user input , records are displayed in the data grid below it. Now the datagrid has a large no. of...
0
by: Tim_k | last post by:
Does anyone have an example of how to export a datagrid to an Excel pivot table? The code below exports the grid contents to Excel using the Response object. I'd like to expand it to show the...
2
by: JIM.H. | last post by:
Hello, I have a DataGrid1 object in my asp.net web application, it has 5 columns and it shows data retrieved from a table. That part is ok, I see all the data. I am quite new and I succeeded that...
1
by: shl | last post by:
My app is for data entry over the web. The user enters data into a datagrid on the 1st pg, which I put into a datatable ( this datatable has 10 columns, and could be up to about 100 rows). When...
6
by: Opa | last post by:
Hi, I have a DataGrid, whose sourceI am exporting to Excel. This works fine except for the Column ordering. My datasource is not a datatable, with a typical SELECT statement where I can...
4
by: Tom | last post by:
I have a gridview on all of my web pages in my web app and they all export to excel. I have one page where the gridview is binding to a datatable that i created and only the first column is...
2
by: heba84 | last post by:
i have aproblem when exporting grid view to excel all columns display correct except the arabic ones it SOMETIMES look like garbage I try: Response.Charset = "utf-8"; but it doesnt work ...
6
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1)...
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
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: 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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.