我正在将Gridview数据导出到Excel中 [英] i am exporting the Gridview data into Excel
问题描述
将网格视图数据导出到该代码的excel中,如下所示;
导出按钮代码如下;
Exporting the Grid view data into excel for that code as follows;
Export Button Code as follows;
try
{
string attachment = "attachment; filename=collectiondetails.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
Response.Write("");
Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
Response.Write("<body>");
Response.Write("<table border="1" bordercolor="black">");
Response.Write("<tr>");
Response.Write("<td colspan="5"><center>");
Response.Write("<font size="4" face="Times New Roman">Batchwise fee collection details</font>");
Response.Write("</center></td>");
Response.Write("</tr>");
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.Flush();
Response.Write("<table>");
Response.Write("</body>");
Response.Write("</html>");
Response.End();
}
catch (Exception Ex)
{
Label1.Text = Ex.Message.ToString();
return;
}
当我点击生成时,
i有一个名为Generate的按钮按钮数据显示在gridview中。
然后当我点击导出按钮时,所有网格视图数据都将导出到excel。
源代码如下;
i have one button called Generate when i click the generate button the data is displayed into gridview.
Then when i click the export button all the grid view data will be export into excel.
Source code as follows;
<%@ Page Language="C#" MasterPageFile="~/MAdministration.master" AutoEventWireup="true" CodeFile="BatchWise_FeeCollection_Report.aspx.cs" Inherits="BatchWise_FeeCollection_Report" Title="BatchWise Collection Report" %>
<%@ Register src="CourseListUC.ascx" tagname="CourseList" tagprefix="Uc1" %>
<%@ Register assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
<script runat="server">
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<style type="text/css">
.modalBackground
{
background-color: Yellow;
filter: alpha(opacity=60);
opacity: 0.6;
}
</style>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<contenttemplate>
<div>
<asp:Button ID="BtnGenerate" runat="server" Text="Generate" onclick="BtnGenerate_Click"/>
<%--<asp:ScriptManager ID="ScriptManager1" runat="server">
--%>
<asp:Button ID="BtnExport" runat="server" OnClick="BtnExport_click"
Text="Export" />
<Uc1:CourseList ID="CrsList" runat="server" />
<asp:GridView ID="GridView1" runat="server" BorderColor="#0000C0"
BorderStyle="Solid" BorderWidth="1px" CaptionAlign="Top" CellPadding="4"
ForeColor="#333333" Width="661px">
<footerstyle backcolor="#507CD1" font-bold="True" forecolor="White" />
<rowstyle backcolor="#EFF3FB" />
<pagerstyle backcolor="#2461BF" forecolor="White" horizontalalign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<editrowstyle backcolor="#2461BF" />
<alternatingrowstyle backcolor="White" />
<asp:Panel ID="ModalPanel" runat="server" HorizontalAlign="Center" Style="display: none" BackColor="Green">
All these Units Exists in Another Boxes
<asp:Button ID="btnCancel" runat="server" Text="Close Me" />
<asp:Label ID="Label1" runat="server" Text="Label">
</div>
</contenttemplate>
当我点击导出按钮错误显示如下;
控制''ctl00_ContentPlaceHold 'GridView'类型的er1_GridView1''必须放在带有runat = server的表单标签内。
$来自我的源代码页的b $ b是什么错误。我怎样才能纠正这个错误。
请帮帮我
问候,
Narasiman P.
When i click the export button error shows as follows;
Control ''ctl00_ContentPlaceHolder1_GridView1'' of type ''GridView'' must be placed inside a form tag with runat=server.
from my source code page what is the error. how can i rectify the error.
please help me
Regards,
Narasiman P.
推荐答案
你会用表格标签包围你的所有控件:
you''ll have surround all your controls with a form tag:
<form runat="server">
...
</form>
http://www.w3schools.com/aspnet/aspnet_forms。 asp [ ^ ]
这篇关于我正在将Gridview数据导出到Excel中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!