First, create two classes. One is used to connect with the data (data layer), and the other is used to associate the previous class with the page (logic layer)
Create a JScsrip. js File
The Code is as follows:
Copy codeThe Code is as follows:
Function setPgb (pgbID, pgbValue, pvalues)
{
If (pgbValue <= pvalues)
{
If (lblObj = document. getElementById (pgbID + '_ label '))
{
LblObj. innerHTML = Math. ceil (pgbValue/pvalues) * 100) + '%'; // change the label value
}
If (pgbObj = document. getElementById (pgbID ))
{
Var divChild = pgbObj. children [0];
PgbObj. children [0]. style. width = Math. ceil (pgbValue/pvalues) * 240); // pgbValue;
}
Window. status = "Data Reading number" + pgbValue + ", please wait ";
}
If (pgbValue = pvalues)
{
Window. status = "Data Reading completed ";
ProBar. style. display = "none ";
Table1.style. display = "none ";
}
}
Create a common.css
The Code is as follows:
Copy codeThe Code is as follows:
. Bi-loading-status
{
/** // * Position: absolute ;*/
Width: 250px;
Padding: 1px;
Overflow: hidden;
}
. Bi-loading-status. text {
White-space: nowrap;
Overflow: hidden;
Width: 100%;
Text-overflow: ellipsis;
Padding: 1px;
}
. Bi-loading-status. progress-bar {
Border: 1px solid ThreeDShadow;
Background: window;
Height: 10px;
Width: 100%;
Padding: 1px;
Overflow: hidden;
}
. Bi-loading-status. progress-bar div {
Background: Highlight;
Overflow: hidden;
Height: 100%;
Filter: Alpha (Opacity = 0, FinishOpacity = 100, Style = 1, StartX = 0, StartY = 0, FinishX = 100, FinishY = 0 );
}
Create a progressbar.htm
The Code is as follows:
Copy codeThe Code is as follows:
<Body topmargin = "0" leftmargin = "0">
<Table width = "100%" height = "100%" ID = "Table1" runat = server>
<Tr>
<Td align = "center" valign = "middle">
<DIV class = "bi-loading-status" id = "proBar" style = "LEFT: pixel PX; TOP: 278px" align = "left">
<DIV class = "text" id = "pgbMain_label" align = "left"> </DIV>
<DIV class = "progress-bar" id = "pgbMain" align = "left">
<Div style = "WIDTH: 5%"> </DIV>
</DIV>
</DIV>
</Td>
</Tr>
</Table>
</Body>
Create a Default. aspx File
The front-end code is as follows:
Copy codeThe Code is as follows:
<Head>
<Script language = "javascript" src = "JScript. js" type = "text/javascript"> </script>
</Head>
<Body>
<Form id = "Form1" method = "post" runat = "server">
<Asp: GridView ID = "GridView1" runat = "server">
</Asp: GridView>
</Form>
</Body>
The background code is as follows:
Copy codeThe Code is as follows:
Public partial class _ Default: System. Web. UI. Page
{
DataSet ds;
Text ts = new text ();
Int count = 0;
# Region Page_Load
Private void Page_Load (object sender, System. EventArgs e)
{
If (! Page. IsPostBack)
{
Ds = Getgridview ();
Count = ds. Tables [0]. Rows. Count;
Response. Write ("count =" + count );
String strFileName = Server. MapPath ("progressbar.htm ");
StreamReader sr = new StreamReader (strFileName, System. Text. Encoding. Default );
String strHtml = sr. ReadToEnd ();
Response. Write ("<div style = 'align: center; valign: bottom; '>" + strHtml + "</div> ");
Sr. Close ();
Response. Flush ();
Thread thread = new Thread (new ThreadStart (ThreadProc ));
Thread. Start ();
LoadData (ds );
// Getgridview ();
// Load data
Thread. Join ();
}
}
# Endregion fixedHeader
# Region Getgridview
Protected DataSet Getgridview ()
{
Ds = ts. QueryProcS ("2009/07", "XXXX"); // This is a method in the logic layer.
Return ds;
}
# Endregion
# Region ThreadProc
Private void ThreadProc ()
{
String strScript = "<script> setPgb ('pgbmain', '{0}', '" + count + "'); </script> ";
For (int I = 0; I <= count; I ++)
{
System. Threading. Thread. Sleep (80 );
Response. Write (string. Format (strScript, I ));
Response. Flush ();
}
}
# Endregion LoadData
# Region LoadData
Private void LoadData (DataSet dds)
{
For (int m = 0; m <count; m ++)
{
For (int I = 0; I <dds. Tables [0]. Columns. Count; I ++)
{
}
}
This. GridView1.DataSource = dds. Tables [0]. DefaultView;
This. GridView1.DataBind ();
}
# Endregion Web Form Designer generated code
# Region Web Form Designer generated code
Override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP. NET Web Form Designer.
//
InitializeComponent ();
Base. OnInit (e );
}
/**/
/// <Summary>
/// Required method for Designer support-do not modify
/// The contents of this method with the code editor.
/// </Summary>
Private void InitializeComponent ()
{
// This. Load + = new System. EventHandler (this. Page_Load );
}
# Endregion
}
Shows how to start page loading.
After loading, the data you want to display is automatically displayed.