468,114 Members | 2,095 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,114 developers. It's quick & easy.

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 2089
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Hutty | last post: by
3 posts views Thread by pmud | last post: by
reply views Thread by Tim_k | last post: by
2 posts views Thread by JIM.H. | last post: by
1 post views Thread by shl | last post: by
6 posts views Thread by Opa | last post: by
4 posts views Thread by Tom | last post: by
6 posts views Thread by insirawali | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.