472,958 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 2263
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.