我使用GridView数据导出到Excel代码..
{C}
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" EnableModelValidation="True"
OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowCommand="GridView1_RowCommand"
OnRowCancelingEdit="GridView1_RowCancelingEdit">
<columns>
<asp:TemplateField HeaderText="Product Name">
<itemtemplate>
<asp:Label ID="lblProductName" runat="server" Text='<%# Eval("ProductName") %>'>
</itemtemplate>
<asp:TemplateField HeaderText="Qty">
<itemtemplate>
<asp:Label ID="lblQty" runat="server" Text='<%# Eval("Qty") %>'>
</itemtemplate>
<edititemtemplate>
<asp:TextBox ID="txtQty" runat="server" Text='<%# Eval("Qty") %>' Width="50px">
</edititemtemplate>
<asp:TemplateField HeaderText="Price">
<itemtemplate>
<asp:Label ID="lblPrice" runat="server" Text='<%# Eval("Price") %>'>
</itemtemplate>
<asp:TemplateField HeaderText="Total Price">
<itemtemplate>
<asp:Label ID="lblTotalPrice" runat="server" Text='<%# Eval("Total") %>'>
</itemtemplate>
<asp:TemplateField HeaderText="Edit">
<edititemtemplate>
<asp:LinkButton ID="lnkUpdate" runat="server" Text="Update" CommandName="Update"
CommandArgument='<%# Eval("ProductID") %>'>
<asp:LinkButton ID="lnkCancel" runat="server" CommandName="Cancel" Text="Cancel"
CommandArgument='<%# Eval("ProductID") %>'>
</edititemtemplate>
<itemtemplate>
<asp:LinkButton ID="lblEditItem" runat="server" Text="Edit" CommandName="Edit" CommandArgument='<%# Eval("ProductID") %>' />
</itemtemplate>
<asp:TemplateField HeaderText="Cancel">
<itemtemplate>
<asp:LinkButton ID="lblCancelItem" runat="server" Text="Cancel" CommandArgument='<%# Eval("ProductID") %>'
OnClick="lblCancelItem_Click" />
</itemtemplate>
</columns>
但是当我执行这种方法当时我得到这个错误
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}
我从互联网这个代码
我在哪里错了....