Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
problem is related to tab container of the ajax and there are 4 tab panels are used by me in 1 tab container.and there is one gridview in each tab panel.and there is 1 imagebutton in each tab panel which image button is used by me to export gridview into excel.i have done individually work on every image button according to my requirement.but on the click of that export button gridview is not changing in excel.i have used code which i m sending.its as follows->
C#
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 { }

    }   

one more thing i have used a render method also for this i.e.->
C#
public override void VerifyRenderingInServerForm(Control control)
   {
       //base.VerifyRenderingInServerForm(control);
   }


and 1 more thing that should i have to make 4 methods to render or 1 will work for all?i dnt knw but its not working in it but if i m using this code for 1 individual page in that there is 1 gridview and 1 button to expotrt in that its working properly but not in this case.
plz reply me plz
Posted
Updated 23-Nov-11 20:16pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900