public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { binddate(); } } private void binddate() { try { string connection = ConfigurationManager.AppSettings["ConnectInfo"]; SqlConnection con = new SqlConnection(connection); SqlDataAdapter da = new SqlDataAdapter("select * from quanta", con); DataTable dt = new DataTable(); da.Fill(dt); gv_details.DataSource = dt; gv_details.DataBind(); } catch (Exception ex) { Response.Write(ex.Message); } } public override void VerifyRenderingInServerForm(Control control) { /* verifies the control is rendered*/ } protected void btn_word_Click(object sender, ImageClickEventArgs e) { gv_details.AllowPaging = false; gv_details.DataBind(); Response.ClearContent(); Response.AddHeader("content-disposition", string.Format("attachment;filename={0}", "Doc1.docx")); Response.Charset=""; Response.ContentType="application/ms-word 2007"; StringWriter sw = new StringWriter(); HtmlTextWriter htw=new HtmlTextWriter(sw); gv_details.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)