mannevenu
asked on
to export gridview which is inside update panel to MSExcel
Hello, i have a problem in exporting gridview data to Ecel which is inside update panel. I have used the following code inside updatepanel instead am getting an error which can be seen in below screen shot. Plzzz help me out for this problem.
one more thing the below code is working perfectly in IE 7.0 and mozilla but the problem is when am running it in IE 6.0 what may be the cause for the error.Hope u reply back soon
one more thing the below code is working perfectly in IE 7.0 and mozilla but the problem is when am running it in IE 6.0 what may be the cause for the error.Hope u reply back soon
<Triggers>
<asp:PostBackTrigger ControlID="btnExcelReport"></asp:PostBackTrigger>
</Triggers>
error.bmp
ASKER
hi very gud mrng i used the same code what you have given.but it is showing same error what i posted above ?
can you show me how you call the function? have you specify the filename?
ASKER
ya sure plz go through code which i am attaching
public void ExportGridToExcel(GridView GV, string fileName)
{
Response.Clear();
Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xls", fileName));
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GV.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.Flush();
Response.End();
}
public static void Convert(DataSet ds, HttpResponse Response)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=mp.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();
dg.DataSource = ds.Tables[0];
dg.DataBind();
dg.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
..........................................................................
protected void btnExcelReport_Click1(object sender, ImageClickEventArgs e)
{
{
if (ddlJoboffer.SelectedItem.Text.Equals("All Jobs"))
{
jobdetails();
Convert(ds, Response);
}
else if (ddlJoboffer.SelectedItem.Text.Equals("Particular Job"))
{
if (ddlJoboffertitle.SelectedItem.Text.Equals("-Select-"))
{
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger;alert('Please select Job Title');}", true);
ScriptManager sm = ScriptManager.GetCurrent(this);
sm.SetFocus(ddlJoboffertitle);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "focus", "$get('" + ddlJoboffertitle.ClientID + "').focus();", true);
}
else
{
partcjobdetails();
Convert(ds, Response);
}
}
else if (ddlJoboffer.SelectedItem.Text.Equals("By Date"))
{
if (txtofferfromdate.Text != "")
{
if (txtoffertodate.Text != "")
{
DateTime dt1 = DateTime.Parse(txtofferfromdate.Text);
DateTime dt2 = DateTime.Parse(txtoffertodate.Text);
if (dt2 > dt1)
{
//imgbtnprint.Visible = true;
//btnExcelReport.Visible = true;
jobdetailsbydate();
gdvofferjob.Visible = true;
}
else if(dt1==dt2)
{
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('From date & To date cannot be same.No records found between these dates'); }", true);
}
else
{
gdvofferjob.Visible = false;
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('To date cannot be less than From date'); }", true);
txtofferfromdate.Text = "";
txtoffertodate.Text = "";
ScriptManager.GetCurrent(this).SetFocus(txtofferfromdate);
}
jobdetailsbydate();
Convert(ds, Response);
}
else
{
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Please select To Date'); }", true);
ScriptManager sm = ScriptManager.GetCurrent(this);
sm.SetFocus(txtoffertodate);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "focus", "$get('" + txtoffertodate.ClientID + "').focus();", true);
}
}
else
{
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Please select From Date'); }", true);
ScriptManager sm = ScriptManager.GetCurrent(this);
sm.SetFocus(txtofferfromdate);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "focus", "$get('" + txtofferfromdate.ClientID + "').focus();", true);
}
}
else
{
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Please select option from Report on Jobs Offered'); }", true);
ScriptManager sm = ScriptManager.GetCurrent(this);
sm.SetFocus(ddlJoboffer);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "focus", "$get('" + ddlJoboffer.ClientID + "').focus();", true);
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank u i got solution
I use the following method and with fine in IE6/7 (with update panel and button with
PostBackTrigger)
Open in new window