将数据从gridview下载到excel后如何禁用进度条 [英] How to disable the progress bar after downloading the data from gridview to excel
问题描述
我想在将数据下载到Excel后隐藏进度条。
在运行模式下如下
i有来自数据库的gridview数据。当我点击那个按钮gridview数据下载到excel时,我有一个按钮导出excel。
用于将gridview数据下载到excel代码如下
i want to hide progress bar after downloading the data into excel.
In run mode as follows
i have gridview data from database. i have one Button Export to excel when i click that button gridview data is downloading to excel.
for downloading gridview data to excel code as follows
protected void btnExport_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
string script = "$(document).ready(function () { $('[id*=btnExport]').click(); });";
ClientScript.RegisterStartupScript(this.GetType(), "load", script, true);
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Employee.xls"));
Response.ContentType = "application/ms-excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvEmpdetails.AllowPaging = false;
BindGrid();
//Applying stlye to gridview header cells
for (int i = 0; i < gvEmpdetails.HeaderRow.Cells.Count; i++)
{
gvEmpdetails.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");
}
gvEmpdetails.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
源代码如下
Source code as follows
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.modal
{
position: fixed;
top: 0;
left: 0;
background-color: black;
z-index: 99;
opacity: 0.8;
filter: alpha(opacity=80);
-moz-opacity: 0.8;
min-height: 100%;
width: 100%;
}
.loading
{
font-family: Arial;
font-size: 10pt;
border: 5px solid #67CFF5;
width: 200px;
height: 100px;
display: none;
position: fixed;
background-color: White;
z-index: 999;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function ShowProgress() {
setTimeout(function () {
var modal = $('<div />');
modal.addClass("modal");
$('body').append(modal);
var loading = $(".loading");
loading.show();
var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
loading.css({ top: top, left: left });
}, 200);
}
$('form').live("submit", function () {
ShowProgress();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div align ="Center">
<asp:Label ID="label" Text = "Proof of conecpt" Font-Bold ="True" forecolor ="Blue" runat ="server"></asp:Label>
</div>
<asp:GridView ID="gvEmpdetails" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
<div class="loading" align="center">
Loading. Please wait.<br />
<br />
<img src="loader.gif" alt="" />
</div>
<div>
<asp:Button ID="btnExport" runat="server" Text="Export to Excel" OnClick="btnExport_Click" />
</div>
</form>
</body>
</html>
当我点击在数据显示为excel之后显示Exporttoexcel进度条。
然后我关闭excel。并且在后台进度条正在运行。
i想隐藏进度条。
怎么做。
When i click the Exporttoexcel progress bar displaying after that data is displaying into excel.
Then i close the excel. and in the background progress bar is running.
i want to hide that progress bar.
for that how can do.
推荐答案
(document).ready(function(){
(document).ready(function () {
('[id * = btnExport] ')。click();});;
ClientScript.RegisterStartupScript( this .GetType(), load,脚本, true );
Response.ClearContent();
Response.Buffer = true ;
Response.AddHeader( content-disposition, string .Format( attachment; filename = {0}, Employee.xls));
Response.ContentType = application / ms-excel;
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvEmpdetails.AllowPaging = false ;
BindGrid();
// 将stlye应用于gridview标题单元格
for ( int i = 0 ; i < gvEmpdetails.HeaderRow.Cells.Count; i ++)
{
gvEmpdetails.HeaderRow.Cells [i] .Style.Add( background-color, #df5015跨度>);
}
gvEmpdetails.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
('[id*=btnExport]').click(); });"; ClientScript.RegisterStartupScript(this.GetType(), "load", script, true); Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Employee.xls")); Response.ContentType = "application/ms-excel"; System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); gvEmpdetails.AllowPaging = false; BindGrid(); //Applying stlye to gridview header cells for (int i = 0; i < gvEmpdetails.HeaderRow.Cells.Count; i++) { gvEmpdetails.HeaderRow.Cells[i].Style.Add("background-color", "#df5015"); } gvEmpdetails.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); }
源代码如下
Source code as follows
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.modal
{
position: fixed;
top: 0;
left: 0;
background-color: black;
z-index: 99;
opacity: 0.8;
filter: alpha(opacity=80);
-moz-opacity: 0.8;
min-height: 100%;
width: 100%;
}
.loading
{
font-family: Arial;
font-size: 10pt;
border: 5px solid #67CFF5;
width: 200px;
height: 100px;
display: none;
position: fixed;
background-color: White;
z-index: 999;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function ShowProgress() {
setTimeout(function () {
var modal =
(' < div />');
modal.addClass( modal);
这篇关于将数据从gridview下载到excel后如何禁用进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!