熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

加載大量數據時的loading制作

2022-06-13   來源: .NET編程 

  首先創建數據庫導入測試數據數據庫很簡單結構如下

  

  使用如下sql語句導入條記錄

  declare @i int

  set @i=

  while(@i<)

  Begin

  set @i=@i+

  insert into LargeData(colcolcol) values(第一列數據第二列數據第三列數據 );

  End

  go

  好了測試數據准備完畢現在我們用GridView來顯示這條數據

  Defaultaspx的代碼如下

  代碼

  <%@ Page Language=C# AutoEventWireup=true  CodeFile=Defaultaspxcs Inherits=_Default %>

  <!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN transitionaldtd>

  <html xmlns= >

  <head runat=server>

  <meta httpequiv=contenttype content=text/html;charset=utf />

  <title>Loading</title>

  <script type=text/javascript src=></script>

  </head>

  <body >

  <div id=progressBar >加載中請稍候<img alt=加載中 src=gif/></div>

  <form id=form runat=server>

  <div id=content >

  <asp:GridView ID=GridView runat=server AutoGenerateColumns=False EnableViewState=False>

  <Columns>

  <asp:BoundField DataField=col HeaderText=COL />

  <asp:BoundField DataField=col HeaderText=COL />

  <asp:BoundField DataField=col HeaderText=COL />

  </Columns>

  </asp:GridView>

  </div>

  </form>

  <script type=text/javascript>

  $(#content)show();

  $(#progressBar)fadeOut();

  </script>

  </body>

  </html>

  後台Defaultaspxcs很簡單代碼如下

  代碼

  using System;

  using SystemData;

  using SystemConfiguration;

  using SystemWeb;

  using SystemWebSecurity;

  using SystemWebUI;

  using SystemWebUIWebControls;

  using SystemWebUIWebControlsWebParts;

  using SystemWebUIHtmlControls;

  using SystemDataSqlClient;

  public partial class _Default : SystemWebUIPage

  {

  private const string SQL_GET_NUM = SELECT * FROM [Demo][dbo][LargeData];

  protected void Page_Load(object sender EventArgs e)

  {

  ResponseFlush();

  Bind();

  }

  private void Bind()

  {

  using (SqlConnection con = new SqlConnection(ConfigurationManagerConnectionStrings[SqlConStr]ConnectionString))

  {

  SqlCommand cmd = new SqlCommand(SQL_GET_NUM con);

  cmdConnectionOpen();

  ResponseFlush();

  GridViewDataSource = cmdExecuteReader(CommandBehaviorCloseConnection);

  GridViewDataBind();

  }

  }

  }


From:http://tw.wingwit.com/Article/program/net/201311/11402.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.