页面加载数据量比较大,想在页面接在完成前加一个“数据加载中”,请问如何在asp.net中实现

解决方案 »

  1.   


    给你一定实例吧 
        实例之让页面等待注意建一个页面demo_waittest.aspx文件拷贝代码即可
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="demo_waittest.aspx.cs" Inherits="codeexample_demo_waittest" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html   xmlns="http://www.w3.org/1999/xhtml"   > 
    <head id="Head1"   runat="server"> 
            <title> 无标题页 </title> 
    </head> 
    <body   > 
        实例之让页面等待
            <form   id="form1"   runat="server"> 
              <div   id="popupLoad"         style="display:none;   z-index:   100;   left:   0px;   width:   600px;   position:   absolute;   top:   40px;   height:   300px;   font-size:   xx-large;   vertical-align:   middle;   text-align:   center;"     >       
                                    <!--等待提示的信息-->               等待提示的信息 </div>   
                      <asp:Button   ID="Button1"   runat="server"   OnClick="Button1_Click"   Text="Button"     style="display:inline"/> 
                      <div   id="ReportDiv">                   <asp:GridView   ID="GridView1"   runat="server"> 
                      </asp:GridView> 
                                        
    </div> 
    <script   language="javascript"   type="text/javascript"> 
            
          
            </script> 
            </form> 
            
    </body> 
    </html> 
    [code=C#]using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class codeexample_demo_waittest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Button1.Attributes.Add("onclick", "document.getElementById('popupLoad').style.display='inline';return   true;");
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("id");
            dt.Columns.Add("field1");        System.Random rd = new Random();
            for (int i = 0; i < 20000; i++)
                dt.Rows.Add(new object[] { i + 1, rd.Next(99999) });        dt.AcceptChanges();
            this.GridView1.DataSource = dt;
            this.GridView1.DataBind();        //Page.RegisterStartupScript("js",   " <script> document.getElementById('popupLoad').style.dispaly='none'; </script> "); 
        }
    }
    [/code]
      

  2.   

    一个网页里面放个框架里面没有加载完成前是隐藏的,加载完成后隐藏loading ,显示框架
      

  3.   

    3楼的那种方法不实用,如果GridView1执行的sql代码需要统计的数据非常多,比如统计全年成本,执行10分钟的话。那么就有10分钟是白屏,10分钟后<div   id="popupLoad">还没有出来网页就加载完毕。
      

  4.   

    private void Page_Load(object sender, System.EventArgs e)时写上下面这些语句:

    //进度条
    Response.Write("<div id='mydiv' style='font-size:9pt'>");
    Response.Write("_");
    Response.Write("</div>");
    Response.Write("<script>mydiv.innerText = '';</script>");
    Response.Write("<script language=javascript>;");
    Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
    Response.Write("{var output; output = '数据加载中,请稍候';dots++;if(dots>=dotmax)dots=1;");
    Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText =  output;}");
    Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
    Response.Write("window.setInterval('ShowWait()',1000);}");
    Response.Write("function HideWait(){mydiv.style.display = 'none';");
    Response.Write("window.clearInterval();}");
    Response.Write("StartShowWait();</script>");
    Response.Flush();
    Thread.Sleep(8000);
      

  5.   

    用了6楼的方法
    不过是System.Threading.Thread.Sleep(8000);