用C#进的一个进度条

<% @ Page Language = " C# "  AutoEventWireup = " true "  CodeBehind = " ProgramBar.aspx.cs "  Inherits = " Example.Example.ProgramBar "   %>

<! 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 runat = " server " >
    
< title > 进度条实例 </ title >
</ head >
< body >
    
< form id = " form1 "  runat = " server " >
    
< script type = " text/javascript " >
       
// 开始
      function BeginTrans(msg)
       
{
         ViewText(
"topMsg",msg); 
       }

       
// 显示加载进度
       function ProgramBarInfo(msg,pos)
        
{
          programBar.style.width
= pos + "%";
         ViewText(
"topMsg",msg + " 已完成" + pos + "%");
        }
              
       
// 设置加载时间
      function SetProgramBarTime(msg)
       
{
          ViewText(
"bottomMsg",msg);
       }

       
// 加载结束
       function EndTrans(msg)
        
{
          
if(typeof(msg)=="undefined")
            ViewText(
"topMsg","完成");
           
else
            ViewText(
"topMsg",msg);       
            
        }

       
// 显示文本 
       function ViewText(id,msg)
        
{
          var strTag 
= '<font face="Verdana, Arial, Helvetica" size="2" color="#ea9b02"><B>' + msg + '</B></font>';    
          
if (document.all) document.all[id].innerHTML = strTag;
        }

      
    
</ script >
    
< div style = " text-align:center " >
    
< div id = " topMsg "  style = " width:30%; " > 正在加载....... </ div >
      
< div style = " border:solid 1px #CCC;width:30%; text-align:left "  id = " ProgramSide " >
        
< div id = " programBar "  style = " height:30px; background-color:#316AC5;width:0px; " ></ div >
      
</ div >
      
< div id = " bottomMsg "  style = " width:30%; " ></ div >
    
</ div >
    
< div >
      
<%= response  %>
    
</ div >
    
</ form >
    
    
    
</ body >
</ html >
using  System;
using  System.Collections;
using  System.Configuration;
using  System.Data;
using  System.Linq;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.HtmlControls;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Xml.Linq;

namespace  Example.Example
{
    
public partial class ProgramBar : System.Web.UI.Page
    
{
        
public static string response;
        
protected void Page_Load(object sender, EventArgs e)
        
{
            
if (!IsPostBack)
            
{
                DateTime startTime 
= DateTime.Now;
                DateTime endTime 
= DateTime.Now;
                
string jsBlock;
                
// 处理完成
                response += "<script type="text/javascript">BeginTrans('开始处理...');</script> ";
                
// Response.Write(jsBlock);
                System.Threading.Thread.Sleep(1000);

                
// 根据处理任务处理情况更新进度条
                for (int i = 1; i <= 100; i++)
                
{
                    System.Threading.Thread.Sleep(
20);
                    response 
+= "<script type="text/javascript">ProgramBarInfo('" + "A" + i.ToString() + "','" + i.ToString() + "');</script> ";
                    
//Response.Write(jsBlock);
                }


                
// 处理完成
                response += "<script type="text/javascript">EndTrans('处理完成。');</script> ";
                
//Response.Write(jsBlock);

                
// 用时
                endTime = DateTime.Now;
                response 
+= "<script type="text/javascript">SetProgramBarTime('用时" + GetTimeSpan(startTime, endTime) + "');</script>";
                
//Response.Write(jsBlock);
            }

           
        }


        
protected string GetTimeSpan(DateTime startTime, DateTime endTime)
        
{
            
string timeSpan = string.Empty;
            TimeSpan ts 
= endTime - startTime;
            
if (ts.Days > 0)
                timeSpan 
+= ts.Days.ToString() + "";
            
if (ts.Hours > 0)
                timeSpan 
+= ts.Hours.ToString() + "小时";
            
if (ts.Minutes > 0)
                timeSpan 
+= ts.Minutes.ToString() + "分钟";
            
if (ts.Seconds > 0)
                timeSpan 
+= ts.Seconds.ToString() + "";
            
return timeSpan;
        }

    }

}

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值