예제 #1
0
        protected void BtnExcel_Click(object sender, EventArgs e)
        {
            if (GV1.Rows.Count < 1)
            {
                Misc.Message(Response, "无数据要导出!");
                return;
            }
            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment; filename=wuzixuqiu.xls");
            Response.ContentType = "application/excel";
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            GV1.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();
        }
예제 #2
0
    protected void btnExportWord_Click(object sender, EventArgs e)
    {
        try
        {
            //////////////////////////////////////
            GV1.AllowPaging = false;
            QueryFunc(TbQRID.Text);
            GV1.Columns[8].Visible = false;
            GV1.Columns[9].Visible = false;
            /////////////////////////////////////
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.doc");
            Response.Charset     = "";
            Response.ContentType = "application/vnd.ms-word ";
            StringWriter   sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            GV1.AllowPaging = false;
            GV1.DataBind();
            QueryFunc(TbQRID.Text);
            //GV1.Columns[8].Visible = false;
            //GV1.Columns[9].Visible = false;

            GV1.RenderControl(hw);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();

            //////////////////////////////////////
            GV1.Columns[8].Visible = true;
            GV1.Columns[9].Visible = true;
            /////////////////////////////////////
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + "حدث خطأ : " + ex.Message + "')</script>");
        }
    }
예제 #3
0
    ////////////////////////////////////////////////////////////////
    protected void PrintCurrentPage(object sender, EventArgs e)
    {
        try
        {
            GV1.Columns[8].Visible    = false;
            GV1.Columns[9].Visible    = false;
            GV1.PagerSettings.Visible = false;
            GV1.DataBind();
            QueryFunc(TbQRID.Text);

            StringWriter   sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GV1.RenderControl(hw);
            string gridHTML = sw.ToString().Replace("\"", "'")
                              .Replace(System.Environment.NewLine, "");
            StringBuilder sb = new StringBuilder();
            sb.Append("<script type = 'text/javascript'>");
            sb.Append("window.onload = new function(){");
            sb.Append("var printWin = window.open('', '', 'left=0");
            sb.Append(",top=0,width=1000,height=600,status=0');");
            sb.Append("printWin.document.write(\"");
            sb.Append(gridHTML);
            sb.Append("\");");
            sb.Append("printWin.document.close();");
            sb.Append("printWin.focus();");
            sb.Append("printWin.print();");
            sb.Append("printWin.close();};");
            sb.Append("</script>");
            ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
            GV1.PagerSettings.Visible = true;
            GV1.DataBind();
            QueryFunc(TbQRID.Text);
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + "حدث خطأ : " + ex.Message + "')</script>");
        }
    }