Export GridView To Excel xls In ASP Net C# | ProgrammingGeek

preview_player
Показать описание

code
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/ms-excel";
Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{

}

Note that you must add method VerifyRenderingInServerForm() in the cs file to avoid rendering error.

------
This channel covers all the programming tutorial related with .Net- C#, linq, VB, SQL, Android, HTML, CSS, jQuery, Crystal Report and Microsoft Report.
So, Please subscribe and keep in touch.

Visit my page in Facebook
------
More Tags

Рекомендации по теме
Комментарии
Автор

This is working fine. I have tried enough. After watching this error solution in this tutorial I have solved. Thanks. Please upload a tutorial to export selected column from gridview to excel.

aminaali
Автор

Thank for sharing this useful information

soniaaqib
Автор

Excellent tutorial with error solving.

SwiftLearn
Автор

When i am trying to download the xls file by clicking the link button. My page is download in aspx form not xls file why

zaibkhanzada
Автор

Hi, I too tried the same. I have 2 aspx file. In one file it is working fine and downloading the file but in another file, the excel file is generating but not showing the download option and not downloading in default path. sould you please spread some light??

Sunshine-mpni
Автор

I tried alot but this is helpful
Thank you

tabishinstagram
Автор

when grid view is in table then not working even VerifyRenderingInServerForm not valid showing. no body explained where used gridview under table tr td tag

gauravseth
Автор

Bro, great video. However, your title is misleading, it should xls instead of xlsx.

weikangyeoh