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

G

Guest

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
 
G

Guest

Thanks Raterus. This was helpful.

Raterus said:
Check this out,
http://weblogs.asp.net/dneimke/archive/2004/01/27/63348.aspx

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

--Michael

pmud said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top