Hi eveyone!
I have this problem, so I'll appreciate very much any help (hopefully a code example).
The settings:
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!
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
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¶m1=val1¶m2=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>