Dear Sir
Please help me to add new rows at top of Excel sheet while exporting to Excel from GridView and how to stop running loader.
<%-- Start Exchange Rate list --%>
<div class="container mb-0 mt-0 ">
<div class="row g-0 pt-0 " style="">
<asp:Panel ID="Panel1" runat="server">
<div class="col col-12 justify-content-center">
<asp:GridView ID="GvExchangeRate" Font-Size="10px" runat="server"
Style="width: 80%; align-items: center; border-collapse: collapse;"
AutoGenerateColumns="false" CssClass="MyDataGridViewListTwo"
EmptyDataText="No Record Found"
EmptyDataRowStyle-ForeColor="Red"
EmptyDataRowStyle-Font-Bold="true"
EmptyDataRowStyle-BorderStyle="None"
HorizontalAlign="Left"
AllowSorting="true"
OnSorting="OnSorting" OnRowDataBound="GvExchangeRate_RowDataBound">
<RowStyle CssClass="rows"></RowStyle>
<Columns>
<asp:TemplateField HeaderText="Sr.No" ItemStyle-Width="30" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblRowNumber" Text='<%# Container.DataItemIndex + 1 %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SetDate" HeaderText="Active Date" SortExpression="SetDate" ItemStyle-Wrap="False" DataFormatString="{0:dd-MMM-yyyy}"></asp:BoundField>
<asp:BoundField DataField="DeactiveDate" HeaderText="Deactive Date" SortExpression="DeactiveDate" ItemStyle-Wrap="False" DataFormatString="{0:dd-MMM-yyyy}"></asp:BoundField>
<asp:BoundField DataField="Currency" HeaderText="Currency" ItemStyle-Wrap="False"></asp:BoundField>
<asp:BoundField DataField="ExchangeRate" HeaderText="ExchangeRate" ItemStyle-Wrap="False"></asp:BoundField>
<asp:BoundField DataField="ActiveStatus" HeaderText="ActiveStatus" ItemStyle-Wrap="False"></asp:BoundField>
</Columns>
</asp:GridView>
</div>
</asp:Panel>
</div>
<br />
<br />
</div>
<%-- End Currency list --%>
<%-- Start Export To Export --%>
<div class="container mb-0">
<div class="row g-0 " style="background-image: linear-gradient(to right, #e6d2fa ,#e6d2fa);">
<div class="col-12 d-flex justify-content-start">
<div class="h-10 align-items-center justify-content-start">
<div style="background: lightgray">
<img id="loader1" style="display: none;" src="https://www.aspsnippets.com/demos/loader.gif" alt="" />
</div>
</div>
<asp:Button ID="BtnExportToExcel" CssClass="btn btn-info btn-outline-success"
OnClientClick="showLoader1();"
runat="server" Text="Export To Excel" OnClick="BtnExportToExcel_Click" />
</div>
</div>
</div>
protected void BtnExportToExcel_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(7000);
//==============================================
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=ExchangeRateHistory.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter hw = new HtmlTextWriter(sw);
//To Export all pages
GvExchangeRate.AllowPaging = false;
//this.LoadAllList();
GvExchangeRate.HeaderRow.BackColor = Color.White;
foreach (TableCell cell in GvExchangeRate.HeaderRow.Cells)
{
//cell.BackColor = GvPaymentStatus.HeaderStyle.BackColor;
cell.ForeColor = Color.Black;
cell.Font.Bold = true;
cell.Font.Size = 12;
cell.BackColor = Color.LightCyan;
}
foreach (GridViewRow row in GvExchangeRate.Rows)
{
row.BackColor = Color.White;
row.Font.Size = 10;
foreach (TableCell cell in row.Cells)
{
if (row.RowIndex % 2 == 0)
{
cell.BackColor = GvExchangeRate.AlternatingRowStyle.BackColor;
}
else
{
cell.BackColor = GvExchangeRate.RowStyle.BackColor;
}
cell.CssClass = "textmode";
}
}
GvExchangeRate.RenderControl(hw);
//style to format numbers to string
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
}
// End export to excel
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}