Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export datagrid to Excel

Status
Not open for further replies.

iaswnidou

Programmer
Apr 19, 2005
140
0
0
GR
Hello

I have a datagrid and one of its Templatecolumns contains a dropdownlist in its ItemTemplate.

When i try to export this in excel, the values of this column do not appear, i only see the headertext. Have you come across this problem before?


Here is the code i use in a button click:
Code:
dgEmployee.AllowPaging = false;
dgEmployee.Visible = true;			

DataTable dt = (DataTable) ViewState["Employees"];
dgEmployee.DataSource = dt;
dgEmployee.DataBind();
dgEmployee.Columns[0].Visible = false; 
dgEmployee.Columns[1].Visible = false; 
			
Response.Clear(); 
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
				
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
			
this.ClearControls(dgEmployee);			
dgEmployee.RenderControl(oHtmlTextWriter);		
Response.Write(oStringWriter.ToString());
Response.End();

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top