ASP.NET Auto refresh gridview updatepanel timer
Hi
I'm new to ajax.
I'm working on visual studio 2005
. I install the ajax Min4setup and I add the control toolkit to the controls toolbar.
I created a new website Ajax-Enabled then I add the existing items (all the page) from the old web site to the new one.
I wrote the code below in the page.aspx and the other code in page.aspx.vb but nothing happens, the timer event is not firing.
Code:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="8000" Enabled="true">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="test" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Width="616px" BorderStyle="Outset">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="Sender" HeaderText="Sender"
SortExpression=开发者_开发百科"MO_NICKNAME_SOURCE_LOG_HIS" />
<asp:BoundField DataField="DataChat" HeaderText="Conversation" SortExpression="DataChat" />
<asp:TemplateField HeaderText="Date" SortExpression="DATETIMEIN_LOG_HIS">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("DATETIMEIN_LOG_HIS") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("DATETIMEIN_LOG_HIS") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:OfflineChat_ConnectionString %>"
SelectCommand="SP_GET_OFFLINE_USER_CHAT" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="MO_OFFLINEUSER" SessionField="ID" Type="String" />
<asp:QueryStringParameter Name="MO_NICKNAME_REALUSER" QueryStringField="realuserNick"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
{
Label1.Text = "Grid Refreshed at: "
'& DateTime.Now.ToString
GridView1.DataBind()
UpdatePanel1.Update();
}
Any idea or suggestion will be highly appreciated.
Best Regards,
Start the timer with timer1.Start()
.
Clear the GridView, set GridView1.DataSet = null
and reload the Bindings.
精彩评论