dynamicweb09
asked on
Export to excel with c# custom Control
I want to create custom Button control in c#.On Click on the Button the data in gridview will be Exported To Excell.
i have tried.
Below are some code
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
foreach (Control c in this.Page.Controls)
{
String s = c.GetType().ToString();
if (c is GridView)
{
GridView gv = (GridView)c;
if (gv != null)
{
ExportToExcell(gv);
}
}
}
}
public void ExportToExcell(GridView gv)
{
string attachment = "attachment; filename=Data.xls";
Context.Response.ClearCont
Context.Response.AddHeader
Context.Response.ContentTy
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
gv.Parent.Controls.Add(frm
frm.Attributes["runat"] = "server";
frm.Controls.Add(gv);
frm.RenderControl(htw);
Context.Response.Write(sw.
Context.Response.End();
}
ASKER
how will i write all the code within custom control.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://forums.asp.net/p/975095/1237999.aspx#1237999
to convert the DataTable to Excel
Open in new window