Reputation: 3578
How to refresh the gridview without refreshing the whole-page?
I have this code:
<asp:Timer ID="Timer1" runat="server" Interval="3600000">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" Height="250px" Width="250px">
<asp:GridView ID="Gridview1" runat="server" ></asp:GridView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
The Gridview1
's datasource should be filled from code-behind (based on the real-hour), for example:
Dim DT As New System.Data.DataTable
Dim reader As SqlCeDataReader
Using myCEConnection As New SqlCeConnection(myCEConnectionString)
myCEConnection.Open()
Using myCommand As SqlCeCommand = myCEConnection.CreateCommand()
myCommand.CommandText = "SELECT ScheduleID FROM Schedule " & _
"WHERE (Hour = '"& Hour(Now) &"')"
reader = myCommand.ExecuteReader()
DT.Load(reader)
End Using
myCEConnection.Close()
End Using
Gridview1.DataSource = DT.DefaultView
Gridview1.DataBind()
The Gridview1
should be refreshed every 1 hour. I tried the code but get nothing. How can I do that? Thank you in advance.
Upvotes: 1
Views: 6883
Reputation: 939
Did you write this code on Timer's Tick Event ?
Ideally it should be on Timer's Tick event. Your timer doesn't have any TICK Event associated. It should be updated with ontick event (example given below):
<asp:Timer ID="timer" runat="server" ontick="timer_Tick"></asp:Timer>
Upvotes: 3