返回首页

大家好,

我有要求,即出口到Excel中的母版页的gridview的数据。虽然我试图出口我获得sys.webforms.pagerequestmanagerparsererrorexception错误。任何一个,请帮我出关于这个问题。我曾尝试以不同的方式,像如下
1。

DataTable dt = BindCompanies();

        string attachment = "attachment; filename=Employee.xls";

        Response.ClearContent();

        Response.AddHeader("content-disposition", attachment);

        Response.ContentType = "application/vnd.ms-excel";

        string tab = "";

        foreach (DataColumn dc in dt.Columns)

        {

            Response.Write(tab + dc.ColumnName);

            tab = "\t";

        }

        Response.Write("\n");

        int i;

        foreach (DataRow dr in dt.Rows)

        {

            tab = "";

            for (i = 0; i < dt.Columns.Count; i++)

            {

                Response.Write(tab + dr[i].ToString());

                tab = "\t";

            }

            Response.Write("\n");

        }

        Response.End();

(2)
{C}
的问候,
jeevan。

回答

评论会员:Tejas_Vaishnav 时间:2012/02/06

protected void Export2Excel()

{

try

{

    this.GridView1.AllowPaging = false;

    this.GridView1.AllowSorting = false;

    this.GridView1.EditIndex = -1;

 

    // Let's bind data to GridView

    this.BindData();

 

    // Let's output HTML of GridView

    Response.Clear();

    Response.ContentType = "application/vnd.xls";

    Response.AddHeader("content-disposition",

            "attachment;filename=MyList.xls");

    Response.Charset = "";

    StringWriter swriter = new StringWriter();

    HtmlTextWriter hwriter = new HtmlTextWriter(swriter);

    GridView1.RenderControl(hwriter);

    Response.Write(swriter.ToString());

    Response.End();

}

catch (Exception exe)

{

    throw exe;

}

 

}       


使用此代码,并尝试它会为我工作...

还照顾,你不把你的网格方更新面板或会导致这样的错误...

{体C3}
评论会员:游客 时间:2012/02/06
Sarvesh库马尔・古普塔:嗨使用下面的链接:imgsrc=]。这是一个在这种情况下,非常方便。|