Like, I want to call the export function when user click on this link.
Click here to Export to Excel
I tried this but it's not working.
<a href="Export2Excel()" id="link">Export to Excel</a><br />
Expand|Select|Wrap|Line Numbers
- protected void Export2Excel()
- {
- Response.Clear();
- Response.Buffer = true;
- Response.AddHeader("content-disposition", "attachment;filename=EmployeeList.xls");
- Response.Charset = "";
- Response.ContentType = "application/vnd.ms-excel";
- StringWriter sw = new StringWriter();
- HtmlTextWriter hw = new HtmlTextWriter(sw);
- GridView2.AllowPaging = false;
- GridView2.DataBind();
- for (int i = 0; i < GridView2.Rows.Count; i++)
- {
- GridViewRow gvRow = GridView2.Rows[i];
- }
- GridView2.RenderControl(hw);
- Response.Output.Write(sw.ToString());
- Response.Flush();
- Response.End();
- }