Dowload Data gridviewDatabind() every 10 seconds without refreshing the page. RRS feed

  • Question

  • User-1123701243 posted


    I have a page containing a Gridview and some other items. The gridview is getting data from database.

            <asp:UpdatePanel ID="uplCheck" runat="server" class="updatepanel">
                    <asp:GridView ID="gvwData" runat="server" DataSourceID="sdsTweets" AutoGenerateColumns="false" CssClass="gvwTweets" AllowPaging="true" PageSize="50">
                            <asp:TemplateField HeaderText="م">
                                    <%# Container.DataItemIndex + 1 %>
                                <ItemStyle Width="5%" />
                            <asp:BoundField DataField="T_ID" HeaderText="userID" />
                            <asp:BoundField DataField="T_User" HeaderText="UserName" />
    <asp:SqlDataSource ID="sdsTweets" runat="server"
    ConnectionString="<%$ ConnectionStrings:TA %>" ProviderName="<%$ ConnectionStrings:TA.ProviderName %>">

    The code behind to bind the grid view is as follows:

        Private Sub Fill_GridView()
            sdsData.SelectCommand = "select * from Table1 "
        End Sub

    I call the Fill_GridView at Page_Load event and every thing is fine.

    My table1 is getting updated from another application and the records are changing.

    I want to keep refreshing the gridview periodically (every 20 seconds) without refreshing the page.

    I played with threading , update panels but I don't know what is wrong. 

    Wednesday, February 27, 2019 6:13 AM

All replies

  • Wednesday, February 27, 2019 11:17 AM
  • User-893317190 posted

    Hi human2x,

    If you use timer as mgebhard  has suggested,you  need to rebind your gridview.

     <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                     <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" PageSize="2" AllowPaging="true"></asp:GridView>
                      <asp:Timer ID="Timer1" runat="server"  Interval="10000"  OnTick="Timer1_Tick"></asp:Timer>
           <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EntityDb %>" SelectCommand="SELECT * FROM [customer]"></asp:SqlDataSource>
    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
    End Sub

    Best regards,

    Ackerly Xu

    Thursday, February 28, 2019 5:50 AM