刷新Gridview而不刷新整页(ASP.Net)

时间:2012-05-07 15:37:32

标签: asp.net gridview partial-page-refresh

如何刷新gridview 而不刷新整页

我有这段代码:

<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>

Gridview1的数据源应该从代码隐藏(基于实时)填充,例如:

    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()

{1}}应每1小时更新一次。我尝试了代码,却一无所获。我怎样才能做到这一点?提前谢谢。

1 个答案:

答案 0 :(得分:3)

你是否在Timer的Tick事件上写了这段代码?

理想情况下,它应该是Timer的Tick事件。您的计时器没有任何关联的TICK事件。 它应该用ontick事件更新(下面给出的例子):

<asp:Timer ID="timer" runat="server" ontick="timer_Tick"></asp:Timer>