Example #1
0
    protected void btnExpt_Click(object sender, EventArgs e)
    {
        DataTable dy = null;

        DataTable dz = null;

        IncentiveBusiness obj = new IncentiveBusiness();

        string    MemberId = txtEmployeecode.Text;
        DataTable dt       = obj.GetArticalWisePoints(MemberId);


        if (dt.Rows.Count == 0)
        {
            GridView5.Visible = false;
            Panel1.Visible    = false;
            //   noField.Visible = true;
            //  noField.Text = "No Records Found";
        }
        else
        {
            ViewState["GridViewStudentlist"] = dt;
        }

        //  DataTable dt = (DataTable)ViewState["GridViewStudentlist"];

        string filename = "ArticalWisePointExcel.xls";

        string headerTable = @"<table width='100%' border='1'  align='center'  class='TestCssStyle'><h4>Artical Wise Points Summary<br/></h4></table>";


        HttpContext.Current.Response.Write(headerTable);



        System.IO.StringWriter       tw = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
        DataGrid dgGrid = new DataGrid();

        dgGrid.DataSource = dt;
        dgGrid.DataBind();
        dgGrid.ShowHeader = true;
        dgGrid.RenderControl(hw);

        Response.ContentType = "application/vnd.ms-excel";
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");

        this.EnableViewState = false;
        Response.Write(tw.ToString());
        Response.End();
    }