UpdateProgress和UpdatePanel数据查询时的进度的实现

先看看运行后的结果:

1.

2.

3.

所用到的控件:

1 ScriptManager,UpdateProgress,UpdatePanel

前台代码:

 

  
  
  
  
  1. <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="User_Adm.ascx.cs" Inherits="UI.USER_ADM.User_Adm" %> 
  2.  <link href="../css/index.css"     rel="stylesheet" type="text/css" /> 
  3.   <link href="../css/QCS.css"     rel="stylesheet" type="text/css" /> 
  4.     
  5.     <asp:ScriptManager ID="ScriptManager1" runat="server"> 
  6. </asp:ScriptManager> 
  7. <br /> 
  8. <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
  9. <ContentTemplate> 
  10.     <table ID="table1"  
  11.         style="border-width: thin; border-style: groove; width:100%;" width="100%"  
  12.         align="center" frame="box"> 
  13.         <tr> 
  14.             <td class="style1"> 
  15.                 <asp:Label ID="label" runat="server" Text="用户帐号:"></asp:Label> 
  16.             </td> 
  17.             <td class="style2"> 
  18.                 <asp:TextBox ID="user_name" runat="server" Width="78px"></asp:TextBox> 
  19.             </td> 
  20.             <td class="style3"> 
  21.                 <asp:Label ID="Label2" runat="server" Text="电话号码:"></asp:Label> 
  22.             </td> 
  23.             <td class="style4"> 
  24.                 <asp:TextBox ID="tel" runat="server" Width="78px"></asp:TextBox> 
  25.             </td> 
  26.             <td class="style5"> 
  27.                 <asp:Label ID="Label3" runat="server" Text="真实姓名:"></asp:Label> 
  28.             </td> 
  29.             <td class="style8"> 
  30.                 <asp:TextBox ID="real_name" runat="server" Width="78px"></asp:TextBox> 
  31.             </td> 
  32.             <td class="style9"> 
  33.                 &nbsp;</td> 
  34.         </tr> 
  35.         <tr> 
  36.             <td class="style1"> 
  37.                 <asp:Label ID="Label4" runat="server" Text="电子邮件:"></asp:Label> 
  38.             </td> 
  39.             <td class="style2"> 
  40.                 <asp:TextBox ID="mail" runat="server" Width="78px"></asp:TextBox> 
  41.             </td> 
  42.             <td class="style3"> 
  43.                 <asp:Label ID="Label5" runat="server" Text="角色名称: "></asp:Label> 
  44.             </td> 
  45.             <td class="style4"> 
  46.                 <asp:DropDownList ID="role" runat="server" DataSourceID="SqlDataSource1"  
  47.                     DataTextField="role_name" DataValueField="role_id" Width="78px"  
  48.                     ondatabound="role_DataBound"> 
  49.                 </asp:DropDownList> 
  50.             </td> 
  51.             <td class="style5"> 
  52.                 <asp:Label ID="Label6" runat="server" Text="用户性别:"></asp:Label> 
  53.             </td> 
  54.             <td class="style8"> 
  55.                 <asp:DropDownList ID="sex" runat="server" Width="78px"  
  56.                     ondatabound="sex_DataBound"> 
  57.                     <asp:ListItem>请选择</asp:ListItem> 
  58.                     <asp:ListItem></asp:ListItem> 
  59.                     <asp:ListItem></asp:ListItem> 
  60.                 </asp:DropDownList> 
  61.             </td> 
  62.             <td class="style9"> 
  63.                 <asp:ImageButton ID="ImageButton1" runat="server"  
  64.                     ImageUrl="~/image/btn_search.gif" onclick="ImageButton1_Click" /> 
  65.             </td> 
  66.         </tr> 
  67.     </table> 
  68.     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  69.     <br /> 
  70.     <asp:GridView ID="GridView1" runat="server" Width="100%" BackColor="#F7F6F3"  
  71.         HorizontalAlign="Center"> 
  72.         <AlternatingRowStyle HorizontalAlign="Center" /> 
  73.         <EditRowStyle HorizontalAlign="Center" /> 
  74.         <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" /> 
  75.         <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" /> 
  76.         <RowStyle HorizontalAlign="Center" /> 
  77.         <SelectedRowStyle HorizontalAlign="Center" /> 
  78.     </asp:GridView> 
  79.     <asp:SqlDataSource ID="SqlDataSource1" runat="server"  
  80.         ConnectionString="<%$ ConnectionStrings:ConnctionString %>"  
  81.         SelectCommand="SELECT [role_id], [role_name] FROM [tb_role]"> 
  82.     </asp:SqlDataSource> 
  83.     <br /> 
  84.     <br /> 
  85.     <br /> 
  86.     <br /> 
  87. <br /> 
  88. <br /> 
  89. <asp:UpdateProgress ID="UpdateProgress1" runat="server"> 
  90. <ProgressTemplate> 
  91. <div class="page_loading"> 
  92. <br /> 
  93. <table> 
  94. <tr> 
  95. <td> 
  96. <img src="../image/loading.gif" style="filter: alpha(Opacity=60); opacity: 0.6;" /> 
  97. </td> 
  98. <td> 
  99. 正在加载... 
  100. </td> 
  101. </tr> 
  102. </table> 
  103. <br /> 
  104. </div> 
  105. </ProgressTemplate> 
  106. </asp:UpdateProgress> 
  107. </ContentTemplate> 
  108. </asp:UpdatePanel> 

2.后台代码:

 

  
  
  
  
  1. public partial class User_Adm : System.Web.UI.UserControl 
  2.    { 
  3.        private QCS.BLL.tb_userinfo userinfo = new QCS.BLL.tb_userinfo(); 
  4.        protected void Page_Load(object sender, EventArgs e) 
  5.        { 
  6.  
  7.        } 
  8.        void Generate_Sql()  
  9.        { 
  10.            sb.Append("select user_id 用户编号,user_name 用户名,real_name 真实姓名,role_id 角色编号,work_grop_id 工作组编号,phone 联系方式,sex 性别,email 电子邮件,default1 缺省1,default2 缺省2 from tb_userinfo where 1=1"); 
  11.            if(user_name.Text!=""
  12.            { 
  13.                sb.Append(" and user_name='"+user_name.Text.ToString()+"'"); 
  14.            } 
  15.            if(tel.Text!=""
  16.            { 
  17.                sb.Append(" and phone='"+tel.Text.ToString()+"'");   
  18.            } 
  19.            if(real_name.Text!=""
  20.            { 
  21.                sb.Append("  and real_name='"+real_name.Text.ToString()+"'"); 
  22.            } 
  23.            if(mail.Text!=""
  24.            { 
  25.                sb.Append("  and email='"+mail.Text.ToString()+"'"); 
  26.            } 
  27.            if (role.SelectedValue=="-1"
  28.            { 
  29.                ; 
  30.            } 
  31.            else  
  32.            { 
  33.                sb.Append(" and  role_id ='"+Convert.ToInt32(role.SelectedValue)+"'"); 
  34.            } 
  35.            if (sex.SelectedValue=="请选择"
  36.            { 
  37.                ; 
  38.            } 
  39.            else 
  40.            { 
  41.                sb.Append(" and  sex ='"+sex.SelectedValue+"'"); 
  42.            } 
  43.            
  44.        } 
  45.        private StringBuilder sb=new StringBuilder(); 
  46.  
  47.        protected void ImageButton1_Click( object sender, ImageClickEventArgs e ) 
  48.        { 
  49.            System.Threading.Thread.Sleep(1200); 
  50.            Generate_Sql();  //生成sql代码 
  51.            DataSet ds=new DataSet(); 
  52.            ds=userinfo.Get_Query_Table(sb.ToString()); 
  53.            GridView1.DataSource=ds.Tables[0].DefaultView; 
  54.            GridView1.DataBind();  
  55.        } 
  56.  
  57.        protected void role_DataBound( object sender, EventArgs e ) 
  58.        { 
  59.            ListItem item=new ListItem("请选择""-1"); 
  60.            role.Items.Insert(0,item); 
  61.        } 
  62.  
  63.        protected void sex_DataBound( object sender, EventArgs e ) 
  64.        { 
  65.            ListItem item=new ListItem("请选择""-1"); 
  66.            sex.Items.Insert(0, item); 
  67.        } 
  68.  
  69.    } 

以上运行就可以刚才的结果,谢谢参考!

 

 

 

你可能感兴趣的:(职场,休闲,UpdatePanel,数据库存取进度条,UpdateProgress)