public override void VerifyRenderingInServerForm(Control control) { } try { 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); gv_forms.AllowPaging = false; SearchBlank(); //gv_forms.DataBind(); //Change the Header Row back to white color gv_forms.HeaderRow.Style.Add("background-color", "#FFFFFF"); //Applying stlye to gridview header cells for (int i = 0; i < gv_forms.HeaderRow.Cells.Count; i++) { gv_forms.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_forms.Rows) { gvrow.BackColor = Color.White; if (j <= gv_forms.Rows.Count) { if (j % 2 != 0) { for (int k = 0; k < gvrow.Cells.Count; k++) { gvrow.Cells[k].Style.Add("background-color", "#EFF3FB"); } } } j++; } CheckBox ItemAll = (CheckBox)Convert.ChangeType((gv_forms.HeaderRow.FindControl("chk_all")), typeof(CheckBox)); ItemAll.Visible = false; foreach (GridViewRow row in gv_forms.Rows) { LinkButton lbtnview = (LinkButton)row.FindControl("lbtn_Edit"); LinkButton lbtnedit = (LinkButton)row.FindControl("LinkButton2"); CheckBox Item = (CheckBox)row.FindControl("chk_item"); lbtnview.Visible = false; lbtnedit.Visible = false; Item.Visible = false; gv_forms.Columns[0].Visible = false; gv_forms.Columns[5].Visible = false; gv_forms.Columns[6].Visible = false; } gv_forms.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); } catch { }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)