gridview数据未导出为ex​​cel。 [英] gridview data is not exporting to excel.

查看:64
本文介绍了gridview数据未导出为ex​​cel。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview中有多个页面。但在导出后,只有第一页被导出。如何导出excel中的所有页面?

...............

I am having multiple pages in gridview. but after export, only first page is getting exported. What to do for exporting all pages in excel?
...............

protected void btnExport_Click(object sender, EventArgs e)
    {
        if (lblMsg.Visible == true)
        {
            Response.Redirect("~/Reports.aspx");
        }


        Response.ClearContent();
        Response.AppendHeader("content-disposition", "attachment;filename=FirstExport.xls");
        Response.ContentType = "application/excel";
        StringWriter stringWriter = new StringWriter();
        HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);

        gridName.AllowPaging = false;
        gridName.DataBind();

        gridName.HeaderRow.Style.Add("background-color", "#FFFFFF");
        foreach (TableCell tableCell in gridName.HeaderRow.Cells)
        {
            tableCell.Style["background-color"] = "#A55129";
        }
        foreach (GridViewRow gridViewRow in gridName.Rows)
        {
            gridViewRow.BackColor = System.Drawing.Color.White;
            foreach (TableCell gridViewRowTableCell in gridViewRow.Cells)
            {
                gridViewRowTableCell.Style["background-color"] = "#FFF7E7";
            }
        }

        gridName.RenderControl(htmlTextWriter);
        Response.Write(stringWriter.ToString());
        Response.End();
        gridName.AllowPaging = true;
    }

推荐答案

将Gridview绑定到数据库而不是这个

Bind your Gridview from Database Instead of this
gridName.DataBind();





希望这会对你有所帮助:)



Hope this will help you :)


这篇关于gridview数据未导出为ex​​cel。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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