GridView實時更新數據

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Timer ID="SystemTime" runat="server" Interval="1000" OnTick="SystemTime_Tick"></asp:Timer> 
        <asp:GridView runat="server" CssClass="dropdownlist" ID="GridView1" AutoGenerateColumns="false" CellPadding="4" Width="100%" ForeColor="#333333" GridLines="Both" AllowPaging="True" RowStyle-HorizontalAlign="Center">
            <Columns>
                 <asp:BoundField DataField="name" HeaderText="姓名" />
                 <asp:BoundField DataField="data1" HeaderText="數據1" />
                 <asp:BoundField DataField="data2" HeaderText="數據2" />
                 <asp:BoundField DataField="time" HeaderText="時間" DataFormatString="{0:yyyy-MM-dd HH:mm:ss}" />
            </Columns>


            <%--定義表頭的樣式屬性--%>
            <HeaderStyle BackColor="#1CB89E" HorizontalAlign="Center" />
            <%--定義表中的行的樣式屬性--%>
            <RowStyle Font-Size="14px" BackColor="#5BD5C1" />
            <%--定義表中每隔一行的樣式屬性--%>
            <AlternatingRowStyle BackColor="#e6e6e6" />


        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>


//實時更新數據
protected void SystemTime_Tick(object sender, EventArgs e)
{
    GridViewBind();     //重新綁定GridView
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章