By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,783 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,783 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.