我有一个updatepanel
,里面有label
和datalist
,如下
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="2000" Enabled="True" ontick="Timer1_Tick"></asp:Timer>
Tick <asp:Label ID="LabelTick" runat="server" Text=""></asp:Label>
<asp:DataList ID="dl1" runat="server" DataSourceID="SqlDataSource1" RepeatColumns = "4" CellSpacing = "3" RepeatLayout = "Table">
<ItemTemplate>
...
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" SelectCommand="SELECT ..."></asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
在后面的代码中,我在每次勾选后更新数据绑定:
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
dl1.DataSourceID = SqlDataSource1.ID
dl1.DataBind()
LabelTick.Text = DateTime.Now.ToString()
End Sub
label
每2秒正确更新一次,这意味着计时器运行正常。但是DataList
没有刷新,它只在页面加载后刷新一次。为什么?
在tick调用结束时:
UpdatePanel1.Update()