asp.net定时刷新局部信息
主要用到:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 |
<asp:ScriptManager ID= "ScriptManager1"
runat= "server"
/> <asp:Timer ID= "Timer1"
OnTick= "Timer1_Tick"
runat= "server"
Interval= "10000"
/> <asp:UpdatePanel ID= "StockPricePanel"
runat= "server"
UpdateMode= "Conditional" > <Triggers> <asp:AsyncPostBackTrigger ControlID= "Timer1"
/> </Triggers> <ContentTemplate> Stock price is
<asp:Label id= "StockPrice"
runat= "server" ></asp:Label><BR /> as
of <asp:Label id= "TimeOfPrice"
runat= "server" ></asp:Label> <br /> </ContentTemplate> </asp:UpdatePanel> |
后台:
1
2
3
4
5 |
protected
void Timer1_Tick( object
sender, EventArgs e) { StockPrice.Text = GetStockPrice(); TimeOfPrice.Text = DateTime.Now.ToLongTimeString(); } |
我主要在LIstView或者GridView中定时刷新数据:
<table class="TableStyle"> <tr> <td> 地块:<asp:DropDownList ID="ddl_Ground" runat="server" AutoPostBack="true"> </asp:DropDownList> </td> </tr> </table> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="20000" /> <asp:UpdatePanel ID="StockPricePanel" runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" /> </Triggers> <ContentTemplate> <asp:ListView ID="QiFang_Data_List" runat="server" DataSourceID="QiFang_Datasource"> <LayoutTemplate> <table id="UserData" class="TableSub"> <tr> <th scope="col"> <asp:Label ID="Label1" runat="server" Text="所属地块" /> </th> <th scope="col"> <asp:Label ID="LinkButton1" runat="server" Text="户型" /> </th> <th scope="col"> <asp:Label ID="LinkButton3" runat="server" Text="已选房源" /> </th> <th scope="col"> <asp:Label ID="LinkButton2" runat="server" Text="房源总数" /> </th> </tr> <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder> </table> </LayoutTemplate> <ItemTemplate> <tr> <td> <%#Eval("G_NAME")%> </td> <td> <%#Eval("ROOM_SHAPE")%> </td> <td> <%#Eval("YiXuanCount")%> </td> <td> <%#Eval("QiFangCount")%> </td> </tr> </ItemTemplate> <EmptyItemTemplate> 没有数据 </EmptyItemTemplate> </asp:ListView> <div class="PageSize"> <%--分页控件--%> <asp:DataPager ID="DataPager1" runat="server" PagedControlID="QiFang_Data_List" EnableViewState="false" PageSize="12"> <Fields> <asp:TemplatePagerField> <PagerTemplate> 共<%=DataCount%>条记录, 当前第<asp:Label runat="server" ID="CurrentPageLabel" Text="<%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" />/<asp:Label runat="server" ID="TotalPagesLabel" Text="<%# Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize) %>" />页, </PagerTemplate> </asp:TemplatePagerField> <asp:NextPreviousPagerField ButtonType="Image" ButtonCssClass="PageCss" ShowFirstPageButton="true" ShowPreviousPageButton="true" ShowLastPageButton="false" ShowNextPageButton="false" FirstPageText="首页" PreviousPageText="上页" FirstPageImageUrl="~/Images/page1.png" PreviousPageImageUrl="~/Images/page3.png" /> <asp:NumericPagerField /> <asp:NextPreviousPagerField ButtonType="Image" ShowNextPageButton="true" ButtonCssClass="PageCss" ShowLastPageButton="true" ShowFirstPageButton="false" ShowPreviousPageButton="false" LastPageText="末页" LastPageImageUrl="~/Images/page2.png" NextPageImageUrl="~/Images/page4.png" NextPageText="下页" /> </Fields> </asp:DataPager> </div> <asp:ObjectDataSource ID="QiFang_Datasource" runat="server" SelectMethod="Get_QiFang_Data" TypeName="BQ.BLL.FangYuan.QiFangManager" MaximumRowsParameterName="pageSize" StartRowIndexParameterName="startIndex" EnablePaging="True" SelectCountMethod="Get_Count" EnableViewState="false" UpdateMethod="Update_QiFang_Room"> <SelectParameters> <asp:ControlParameter ControlID="ddl_Ground" Name="GR_ID" Type="Int64" PropertyName="SelectedValue" /> </SelectParameters> </asp:ObjectDataSource> </ContentTemplate> </asp:UpdatePanel>
后台在定时事件中进行数据重新绑定:
protected void Timer1_Tick(object sender, EventArgs e) { QiFang_Data_List.DataBind(); }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。