如何将更新面板内的Gridview导出到Excel [英] How To Export Gridview Inside Update Panel to Excel

查看:86
本文介绍了如何将更新面板内的Gridview导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All

我想将gridview数据导出到excel,因为我已经完成了这个代码工作正常而没有updatepanel



Hello All
I Want to export the gridview data to excel for that i have done this code is working properly without updatepanel

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 { }



此代码正常运行没有更新面板。

当我们使用更新面板时(更新面板内的网格视图)然后它无法正常工作PLZ帮助我

在此先感谢。


this code is working properly without update panel.
bet when we use update panel(Grid view inside the update panel)then it is not working plz help me
Thanks In Advance.

推荐答案

您可以使用此自定义控件

导出到Excel
You can use this custom control
Export to Excel


使用带有控件ID的回发触发器来导出按钮
By using Post back Triggers with Control id to Button to export


这篇关于如何将更新面板内的Gridview导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆