1

I have a webpage that is just a bunch of gridviews on the page, they display data pulled from a SQL database (using Stored procedures). I have the whole page using a javascript defined refresh function, and it works great (timer is set for every 10 mins).

I have one Gridview that I want to refresh every 15 seconds (they want that data to be the most current always). I have tried 3 different ways to get this functionality, but each has the same side effect. Instead of refreshing that specific gridview, it makes another gridview at the top of the page with the data. I'm not sure what I'm missing here, so any help would be appreciated.

Below is the code for the grid view I'm having issues with, if you need more code, please let me know.

<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="PDUpdatePanel" UpdateMode="Conditional" runat="server">
            <Triggers>                    
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
            <ContentTemplate>
                <asp:Timer ID="Timer1" runat="server" Interval="15000">
                </asp:Timer>
                <td valign="top">
                    <asp:GridView ID="PD" AutoGenerateColumns="true" runat="server">
                    </asp:GridView>
                </td>
            </ContentTemplate>
        </asp:UpdatePanel>

EDIT

I have tried the above (using the script Manager/UpdatePanel/Trigger), I have tried using this (using the Timer1_Tick to call to rebind)

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="PDUpdatePanel" UpdateMode="Conditional" runat="server">

            <ContentTemplate>
                <asp:Timer ID="Timer1" runat="server" Interval="15000" ontick="Timer1_Tick">
                </asp:Timer>
                <asp:Panel runat="server">
                <td valign="top">
                    <asp:GridView ID="PD" AutoGenerateColumns="true" runat="server">
                    </asp:GridView></asp:Panel>
                </td>
            </ContentTemplate>
        </asp:UpdatePanel>

When this I tried the simple, just call the SP and rebind

protected void Timer1_Tick(object sender, EventArgs e)
    {
        DataAccess.PDGet(GridView PD);
    }

public static void PDGet(GridView PD)
    {
        //Create connection
        using (AdoConnNet conn = new AdoConnNet(Config.GetConfigKeys("AppName"), Config.GetConfigKeys("LogPath")))
        {
            conn.SetConnection(Config.GetConfigKeys("SERV_CONVEYOR"), "Conveyor");
            string spTimeOutCountGet = Config.GetConfigKeys("TimeOutCountGet");

            using (SqlCommand cmd = new SqlCommand())
            {
                //Call SP and load the results
                using (SqlDataReader dr = conn.RunSPReturnDataReader(spTimeOutCountGet, cmd))
                {
                    PD.DataSource = dr;
                    PD.DataBind();
                }
            }
        }
    }

Lastly, I tried making a helper function one that get the data from the Database, and another to do the binding (grasping at straws at this point).

The side effect is the same with every way I tried. Instead of refreshing the GridView PD in it's current location, it makes a new Gridview at the top of the page (and pushing the rest of the gridviews down). I'm not savvy with Web pages, so I'm unsure why it's drawing it at the top instead it's current location.
Thanks for the help!

Samwise
  • 11
  • 2
  • add javascript you use to refresh the page please – ale Sep 26 '14 at 13:39
  • @wintermute OP has PostBackTrigger in there that I assume takes care of that. – mxmissile Sep 26 '14 at 13:40
  • Please post what you have tried and what side effects you have faced, maybe we can find a solution to them. This is very unclear right now. First thing coming into my mind, just create a web service and pull data from it every 15 secons using javascript and give it do the grid you want. – Sefa Sep 26 '14 at 13:44
  • Using an UpdatePanel with a timer isn't the best way to keep your table updated. I created [a question](http://stackoverflow.com/questions/25829343/how-to-implement-real-time-data-for-a-web-page) that shows several better ways to implement this (and most of them have the benefit of the page not reloading, you won't lose scroll position). – mason Sep 26 '14 at 14:07
  • @Mason, I'll give that a try. But The issue isn't Scroll position, it's refresh the proper gridview instead of making a new one at the top. Though maybe "losing scroll position" may be the issue. I'll let you know if it works. Thanks! – Samwise Sep 26 '14 at 14:11
  • I'm still having the same issue. Instead of updating the panel need the bottom of the page, where the gridview currently is located, it redraws the gridview at the top with the data (above the title of the page). It will refresh that Gridview every 15 seconds, and once the 10 min timer goes off, the whole page will refresh with data, removing the extra Gridview, and use the gridview it should. Other suggestions? – Samwise Sep 29 '14 at 18:52

0 Answers0