protected void lnk_ViewPolicy_Click(object sender, EventArgs e) { LinkButton lnk = (LinkButton)sender; String s = lnk.CommandArgument; GridBindEmpPolicy.DataSource = PolicyApplicationManagement.GetInstance.GetPolicySelectAll_By_Employee(int.Parse(s)); GridBindEmpPolicy.DataBind(); DetailsView1.DataSource = null; DetailsView1.DataBind(); lbl_HeadingText.Text = "Employee ID In:" + s; Multiview_Policy.SetActiveView(view_GridView); pnlPayment.Visible = false; // foreach (DetailsViewRow gvrow in DetailsView1.Rows) // { // if (j <= DetailsView1.Rows.Count) // { // if (j == 12) // { // for (int k = 0; k < gvrow.Cells.Count; k++) // { // gvrow.Cells[k].Style.Add("background-color", "green"); // gvrow.Cells[k].Style.Add("color", "white"); // } // } // if (j == 16) // { // for (int k = 0; k < gvrow.Cells.Count; k++) // { // gvrow.Cells[k].Style.Add("background-color", "black"); // gvrow.Cells[k].Style.Add("color", "white"); // } // } // if (j == 19) // { // for (int k = 0; k < gvrow.Cells.Count; k++) // { // gvrow.Cells[k].Style.Add("background-color", "black"); // gvrow.Cells[k].Style.Add("color", "white"); // } // } // if (j == 20) // { // for (int k = 0; k < gvrow.Cells.Count; k++) // { // gvrow.Cells[k].Style.Add("background-color", "maroon"); // gvrow.Cells[k].Style.Add("color", "white"); // } // } // if (j == 21) // { // for (int k = 0; k < gvrow.Cells.Count; k++) // { // gvrow.Cells[k].Style.Add("background-color", "#004600"); // gvrow.Cells[k].Style.Add("color", "white"); // } // } // } // j++; // } }
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); GridBindEmpPolicy.AllowPaging = false; //Change the Header Row back to white color GridBindEmpPolicy.HeaderRow.Style.Add("background-color", "#FFFFFF"); //Applying stlye to gridview header cells for (int i = 0; i < GridBindEmpPolicy.HeaderRow.Cells.Count; i++) { GridBindEmpPolicy.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 GridBindEmpPolicy.Rows) { gvrow.BackColor = Color.White; if (j <= GridBindEmpPolicy.Rows.Count) { if (j % 2 != 0) { for (int k = 0; k < gvrow.Cells.Count; k++) { gvrow.Cells[k].Style.Add("background-color", "#EFF3FB"); } } } j++; } GridBindEmpPolicy.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); }