protected void imgbtn_all_Click(object sender, ImageClickEventArgs e) { try { Response.Buffer = true; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "AllContacts.xls")); Response.ContentType = "application/ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); gv_allcontact.AllowPaging = false; // gv_Employes.DataBind(); //Change the Header Row back to white color gv_allcontact.HeaderRow.Style.Add("background-color", "#FFFFFF"); //Applying stlye to gridview header cells for (int i = 0; i < gv_allcontact.HeaderRow.Cells.Count; i++) { gv_allcontact.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 gv_allcontact.Rows) { gvrow.BackColor = Color.White; if (j <= gv_allcontact.Rows.Count) { if (j % 2 != 0) { for (int k = 0; k < gvrow.Cells.Count; k++) { gvrow.Cells[k].Style.Add("background-color", "#EFF3FB"); } } } j++; } foreach (GridViewRow row in gv_allcontact.Rows) { LinkButton status = (LinkButton)row.FindControl("lbtn_allstatus"); LinkButton email = (LinkButton)row.FindControl("lbtn_allemail"); LinkButton view = (LinkButton)row.FindControl("lbtn_view_all"); LinkButton edit = (LinkButton)row.FindControl("lbtn_editall"); LinkButton del = (LinkButton)row.FindControl("lbtn_delall"); status.Visible = false; email.Visible = false; edit.Visible = false; view.Visible = false; del.Visible = false; gv_allcontact.Columns[8].Visible = false; gv_allcontact.Columns[9].Visible = false; gv_allcontact.Columns[10].Visible = false; gv_allcontact.Columns[11].Visible = false; gv_allcontact.Columns[12].Visible = false; } gv_allcontact.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); } catch { } }
public override void VerifyRenderingInServerForm(Control control) { //base.VerifyRenderingInServerForm(control); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)