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 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: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>
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.