triplebd69
asked on
Excel Export works part time.
I have a webapp that lets the user select the table and columns to build a select statement, that gets passes to a second web form that fills a datagrid.
All this works fine.
On this form I also have a button to let the user export to excel, this only seems to part of the time. It appears that on the times it fails the OnInit and page_load never fire. But I don't see why it only happens part of the time. Or is it an issue with the data in the grid?
Any help would be great.
All this works fine.
On this form I also have a button to let the user export to excel, this only seems to part of the time. It appears that on the times it fails the OnInit and page_load never fire. But I don't see why it only happens part of the time. Or is it an issue with the data in the grid?
Any help would be great.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
private void Page_Load(object sender, System.EventArgs e)
{
da = (DataObject)Session["DataO
string xSel = Session["Select"].ToString
DataSet ds = new DataSet();
if (Page.IsPostBack)
{
if (Session["myDataset"] != null)
{
ds = (DataSet)Session["myDatase
dgAdHoc.DataSource = ds;
dgAdHoc.DataBind();
}
}
else
{
using (OdbcConnection con = new OdbcConnection(Configurati
{
con.Open();
string oCMD = Session["Select"].ToString
OdbcDataAdapter daCMD = new OdbcDataAdapter(oCMD, con);
con.Close();
daCMD.Fill(ds);
Session["myDataset"] = ds;
dgAdHoc.DataSource = ds;
dgAdHoc.DataBind();
}
}
}
And the export button..
private void btExcelX_Click(object sender, System.EventArgs e)
{
//export to excel
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel"
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWrit
this.ClearControls(dgAdHoc
dgAdHoc.RenderControl(oHtm
Response.Write(oStringWrit
//Response.End();
}