void BindEmployeePayComponents() { decimal x = 0; lbl_HeadingText.Text = string.Empty; GridBindEmpPayroll.DataSource = EmployeePayrollManagement.GetInstance.GetEmployeePayrollList(); GridBindEmpPayroll.DataBind(); foreach (GridViewRow gr in GridBindEmpPayroll.Rows) { x = x + decimal.Parse(gr.Cells[22].Text); } txt_NetPayMonth.Text = x.ToString(); lbl_HeadingText.Text = "For period [" + DropDown_Month.SelectedItem.Text + "-" + DropDown_Year.SelectedItem.Text + "] of season " + DropDown_Session.SelectedItem.Text + " on dated :" + txt_DateOfPay.Text; }
protected void btnexport_Click(object sender, EventArgs e) { Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.xls")); Response.ContentType = "application/ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); GridBindEmpPayroll.AllowPaging = false; //Change the Header Row back to white color GridBindEmpPayroll.HeaderRow.Style.Add("background-color", "#FFFFFF"); //Applying stlye to gridview header cells for (int i = 0; i < GridBindEmpPayroll.HeaderRow.Cells.Count; i++) { GridBindEmpPayroll.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1"); } int j = 1; //This loop is used to apply stlye to cells based on particular row foreach (GridViewRow gvrow in GridBindEmpPayroll.Rows) { gvrow.BackColor = Color.White; if (j <= GridBindEmpPayroll.Rows.Count) { if (j % 2 != 0) { for (int k = 0; k < gvrow.Cells.Count; k++) { gvrow.Cells[k].Style.Add("background-color", "#EFF3FB"); } } } j++; } GridBindEmpPayroll.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); }