Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

How to force a DataBind when using LoadOnDemand?

Last post 09-23-2008 11:19 by Chaitanya. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 07-08-2008 18:32

    How to force a DataBind when using LoadOnDemand?

     Hi eveyone!

    I have this problem, so I'll appreciate very much any help (hopefully a code example).

    The settings:

    • I have to display a big bunch of data in a webGrid, so I had to use the LoadOnDemand feature.
    • The data is stored in a Session variable and is provided to the grid using this handler for the InitializeDataSource event:

        Protected Sub MyGrid_InitializeDataSource(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.UltraGridEventArgs) Handles MyGrid.InitializeDataSource
            ' See if this is a first load, or if this is a postback that is not an AJAX postback made by the WebGrid
            If Not IsPostBack AndAlso Not MyGrid.IsXmlHttpRequest Then
                Dim dt As DataTable
                Dim pizarra As New Vbc.Pizarra 
                dt = pizarra.GetMyData(Session.Item("MyEntCode"), My.User.Name)
                Session.Add(DS_OFERTAS_COMPRA, dt)
            End If

            MyGrid.DataSource = CType(Session("GridDS"), DataTable)
        End Sub
     

    The problem: 

    Besides displaying the data, I have to provide to the end user a way to refresh that data based on certain parameters he provides through some textboxes. Once the user clicks a "Refresh" button, the following code is executed:

                        If IsPostBack AndAlso Not MyGrid.IsXmlHttpRequest Then
                            Dim pizarra As New Vbc.Pizarra  
                            Dim dt As DataTable

                            dt = pizarra.GetMyData(Session.Item("MyEntCode"), My.User.Name)
                            Session.Item("GridDS") = dt

                            MyGrid.DataBind()
                        End If

    The idea was to reload the data into the grid with the new dataset (according with the parameters given by the user), however the grid doen't reload the data until a new postback. 

    How can I force this databind to have the data in the grid refreshed everytime the user click my "Refresh" button?

     

    Thanks in advance for your help!

     

    • Post Points: 20
  • 07-09-2008 17:07 In reply to

    Re: How to force a DataBind when using LoadOnDemand?

    If you hand the grid the same datasource it just had, it will attempt to keep all of the current information (columns, selected row, etc).  To force the grid to 'reset', you'll want to set the grid's datasource=null, call databind, then set the datasource to your datatable, and call databind once more.

    Hope this helps,

    -Tony

    Anthony Lombardo
    Lead Technical Evangelist
    Infragistics, Inc.
    Worldwide Evangelism Group

    tonyl@infragistics.com
    blogs.infragistics.com

    • Post Points: 20
  • 07-09-2008 17:48 In reply to

    Re: How to force a DataBind when using LoadOnDemand?

    Answer

    Hi Tony! Thanks a lot for your advice. I tried it before but it didn't work, now I realize that I missed the first databind (after seting the datasource to nothing)

    Anyway, I figured out another way to face this problem, so I want to share it, just in case it could be helpful (together with yours) for someone else:

    What I did was to recall the page (from client side) and send in the Request an specific parameter telling that I want to Refresh the data, together with the param values that user provides (for example some codes and date ranges). Something like:

    window.location.replace("myPage.aspx?action=refresh&param1=val1&param2=val2");

    Then in the InitializeDataSource handler I check for Request params and if I found the instruction to refresh, I get the param values and use them to call the method that provides the data.  Here you have to check the page's IsPostback and grid's IsXmlHttpRequest flags and take your own decisions.

    That is the basic idea, I hope it be as usefull as it has been for me.

     

    Best Regards,

    <Marlon> 

    • Post Points: 20
  • 07-18-2008 13:46 In reply to

    Re: How to force a DataBind when using LoadOnDemand?

    Thanks for sharing that approach - sounds like a great solution.

    Anthony Lombardo
    Lead Technical Evangelist
    Infragistics, Inc.
    Worldwide Evangelism Group

    tonyl@infragistics.com
    blogs.infragistics.com

    • Post Points: 20
  • 09-23-2008 2:37 In reply to

    • Chaitanya
    • Not Ranked
    • Joined on 07-10-2008
    • India
    • Points 85

    Re: How to force a DataBind when using LoadOnDemand?

    Guys,

    I have a similar scenario,

    1. I am using XMLLoadondemand
    2. The data loads fine with any changes to the filtering values [I have few filtering components in the layout]
    3. My grid is editable
    4. I do changes on some of the cells and I try to refresh
    5. In the refresh button I have client dilogbox to alert for the user to commit changes done or cancel
    6. When I choose OK I can save the changes done on the grid successfully
    7. When I choose CANCEL I have a problem in reloading the Previous data in to the grid though I am getting the correct data from the database [With postback ON]
    8. My question is on click of CANCEL how do I recall the original data state of the grid? the grid is failing to reload the fresh data.

    Tried following points provided by you guys:

    1)Binding Null dataset before binding the fresh dataset
    2)Tried Location.Replace but works only with IFRAME (I really dont no why?)

    Thanks in advance,
    Chaitanya...

    He alone live who live for others rest all more dead than alive.
    -Swami Vivekananda
    • Post Points: 5
  • 09-23-2008 11:19 In reply to

    • Chaitanya
    • Not Ranked
    • Joined on 07-10-2008
    • India
    • Points 85

    Re: How to force a DataBind when using LoadOnDemand?

    Guys I found the solution for my problem:

    Basically when we have XMLLoadOnDemand enabled and when we try to cancel the diologbox from the javascript we were allowing that for server round trip to rebind the original grid values. But the grid was failing to bind the original dataset with post back.

    Here is the implementation steps I have added two client side events:

    1. BeforeCellUpdatehandler -> keep the original values in an array with key value pair key being cellId and the value being the actual cell value
    2. AfterCellUpdateHandler  -> keep the Changed values in an array with key value pair key being cellId and the value being the changed cell value
    3. In the refresh click call a function by passing the gridId (Which you can get it in initilize grid event from the client side [store the gridid in a page level variable])
    4. Compare both the arrays and update the approprite row

     Some more points [You may require in the process]:

    • From gridName get GridId
    • From CellId get cellIndex and cellValue
    • From CellId You can get row

    If anybody wants code sample I can provide that,

    Thanks,
    Chaitanya...

     

    He alone live who live for others rest all more dead than alive.
    -Swami Vivekananda
    • Post Points: 5
Page 1 of 1 (6 items)
Powered by Community Server (Commercial Edition), by Telligent Systems