Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AJAX Datagrid Refresh

Status
Not open for further replies.

hawkcg

Programmer
Dec 10, 2001
23
0
0
US
I'm trying to use AJAX or some kind of client-side callback scripting to make my datagrids refresh without having to do a postback everytime. I'm using a master page, which adds a bit to the complexity of it. However, I've got it working to an extent. I'll post some of the code that I've got to see if someone else can tell me where I might be going wrong.

First, on the master page. I've included the javascript functions here.
Code:
function RefreshGrid()
			{
			    currentTime = new Date();
			    var Command="RefreshGrid";
			    var context = new Object();
			    context.CommandName = "RefreshGrid";
			    window.status = currentTime.getHours() + ":" + currentTime.getMinutes() + ":" + currentTime.getSeconds() + " Refreshing data...";
			    setTimeout("RefreshGrid();", 10*1000);
			    <%=m_callbackStr%>
			}
			
			function CallBackHandler(result, context) 
			{
			    if (context.CommandName == "RefreshGrid")
			    {
			        window.status = "Refreshing data...Done";
			    }
			}

At the end of the master page, I'm replacing the timed submit with the refresh code:
Code:
<script language="javascript">
                <!--
                    setTimeout("RefreshGrid();", 10*1000);
                    //setTimeout("document.forms[0].submit();", 60*1000);
                -->
            </script>
That's all the master page handles, since the grids I need to refresh are inside the content panels.

Now on the child page.
Code:
private m_eventArgument As String

    Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
        Dim callBack As String = ""

        Select Case m_eventArgument
            Case "RefreshGrid"
                'LoadGrid()
                gridTest.DataBind()
                callBack = "RefreshGrid"
        End Select

        Return callBack
    End Function

    Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
        m_eventArgument = eventArgument
        Trace.Write(" -- CallbackEvent", "eventArgument: " + eventArgument + ", time: " + Now.ToString)
    End Sub
I'm using the private variable m_eventArgument to just pass the arguments to the GetCallBackResult function.

Like I said, everything seems to be working, but the grid doesn't ever update. I've tried to reload the entire grid and I've tried to just call DataBind() again, but nothing seems to work. Anything that anyone can do to help would be greatly appreciated. If I didn't include something you would like to know, please tell me.

Thanks
 
I dont think that will work, binding the grid on the server side will not change its appearance on the client side as the changed data is not outputted to the client.

therefore your local grid will never get the info from the server to change its contents.

i dont have an immediate solution for the same, but i have heard that the GridView (havent looked much into it) can do this...

Known is handfull, Unknown is worldfull
 
From what i knw AJAX can return data back to client page and also some kind of databinding. You should look into it if you want to do that.

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
I think that's where my problem is. I'm not sure how to get the data back from it.
 
If you want to have a datagrid do a refresh without refreshing the page..

Add an Ajax "Update Panel" to your webpage..

Add the Controls that you want to use inside the "zone" of the Update Panel..

and it should work without any extra action - no fancy code etc..

(of course you need to have an ajax "ScriptManager" on the page and it needs to be enabled for "Partial Postback")

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top