Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 1 page on that i want to export the contents of gridview in the excel sheet and gridview is in the update panel.i want that on the click event of button the gridview's contents should be export in the excel sheet.and the button is outside the gridview.
Posted
Comments
Nilesh Patil Kolhapur 7-Apr-12 6:16am    
where is button is it in update panel
pallavi ajin 7-Apr-12 6:21am    
no button is outside, means on the page.if i will click on that button and gridview data change into excel sheet.and gridview is in the update panel
Nilesh Patil Kolhapur 7-Apr-12 6:30am    
k i ll give u solution try it and give reply

1 solution

Hi,
Try this code in function

Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition","attachment;filename=g.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter ht = new HtmlTextWriter(sw);
gvDisplay.AllowPaging = false;
gvDisplay.DataBind();
gvDisplay.RenderControl(ht);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();

and in aspx.cs page Just write following method

public override void VerifyRenderingInServerForm(Control control)
    {

    }

Good Luck
happy coding
 
Share this answer
 
v2
Comments
pallavi ajin 7-Apr-12 6:41am    
if i am using gridview in update panel then this code is not working.
Nilesh Patil Kolhapur 7-Apr-12 6:43am    
then try to insert button in updatepanel then check k and give reply
pallavi ajin 7-Apr-12 6:52am    
ok thnx
Nilesh Patil Kolhapur 7-Apr-12 6:54am    
then accept solution mam

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900