Hi Everyone,
Can somebody please help me with this.
I have this gridview and I have binded it properly,
now I have a button and I want to export the data inside the datagrid to excel.
I can do this in asp.net because the code is quite easy for the webform
but I am having a hard time in C# and it is a standalone application
I have googled it and found no step by step tutorial
I hope someone can help me
Thank you in advance.

I find this code after searching check this one

string status = PolicyStatusDrpDown.SelectedIndex.ToString()=="0"?"open":"close";
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename="+objRLPCompanyInfo.CompanyAlias+" "+status+" "+DateRangeType.SelectedItem.ToString()+" "+System.DateTime.Today.ToLongDateString()+".xls");
Response.Charset = "";
this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
BindGridControl();
//this.ClearControls(SimpleGridControl1);
SimpleGridControl1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();

details you can check this link it contains a sample applicaiton

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.