Hi,
Can anyone tell me how to refresh a grid which is being populated by using InitializeDataSource?
I've used LoadOnDemand="xml" and trying to bind my grid in a method which I am calling in InitializeDataSource. But, when some action is taken on the screen, I need to refresh the grid for which I tried calling my method to bind the grid again. It's not working. I even tried explicity calling InitializeDataSource which didn't work.
I really need the refresh feature to work according to the requirements. Can someone please help me with some ideas here?
Thanks,
Kala
Kala,
What do you mean by "refresh" in this context? What results are you expecting to get, in response to which actions? If this is server-side processing, is this triggered by a regular postback or an asynchronous callback?
InitializeDataSource is an event, not a method. WebGrid will call it when it needs to, and it can't be directly called. You're likely calling the event handler directly, rather than the event, which won't likely affect your results in the way you're after.
By refresh, I mean processing on server side. Once an aciton is performed by the user in the front end, the rows that he selected should go off. I am already using a postback call to process the records on server side. In this context, the user will be selecting multiple rows by using a checkbox and then ther will be a popup window in which the user selects a user and clicks "save" button in the popup. The server side code for this button performs the fund assignment and at this point of time, we need to refresh the grid with new data. I hope I am being clear with the whole explanation.
How can I achieve this?
Thanks
When you cause a postback, the grid should be automatically refreshing itself, in this scenario. This occurs very early in the page lifecycle, after Init and before Load and most other events.
If you need to refresh the grid's contents later, such as after processing further events, load the current data into your data source (if you don't already have it) and call the grid's DataBind() method.
As a note, you don't need to (and shouldn't) call DataBind() as part of the grid's InitializeLayout event. When you handle this event, the grid will implicitly call DataBind() when the event has completed.
I used gridName.Reset(gridDatasource) and it seems do the trick.
Just to clarify, the DataSourceID is set in the front-end code for the UltraWebGrid. I guess resetting it in the code-behind is what causes the grid to refresh.
I was able to get my grid to refresh/databind using the following code:
protected void btnAddNewRow_OnClick(object sender, EventArgs e){ SQLDataSource1.Insert(); UltraWebGrid1.DataSourceID = SQLDataSource1.ID.ToString();}
When the button is clicked, the row inserts into SQL and then the grid refreshes and shows the new row. The second line of code in the function is what forces the grid to refresh. I hope this works for you like it worked for me. I am not 100% why it worked, but it has been deployed for 2 days and there have been no complaints so far.
Thanks,Wendi
Here is the update I got today from the supprot team:
You can do like below code snippet.
UltraWebGrid1.DataSource=null;UltraWebGrid1.DataBind();
UltraWebGrid1.DataSource= ShowAssignedFunds();UltraWebGrid1.DataBind();
***
It didn't help. I've mailed them back that this solution is not working. Please check out my mail below in detail:
*****
I am unable to refresh the grid this way. I am getting "Failed to compare two elements in the array" error when trying to use Databind the second time. To overcome this, I tried the following two steps which didn't help:
Step1: (in InitializeLayout that occurs after Databind)
e.Layout.Bands[0].Columns.FromKey("Role").IsGroupByColumn = false;e.Layout.ViewType = ViewType.OutlookGroupBy;e.Layout.Bands[0].Columns.FromKey("Role").IsGroupByColumn = true;
Step2: (before even assigning the datasource)
gridFundToAssign.DisplayLayout.Bands[0].SortedColumns.Clear();gridFundToAssign.PerformGroupRows();gridFundToAssign.DisplayLayout.Bands[0].Columns.Clear();gridFundToAssign.Clear();gridFundToAssign.ResetBands();gridFundToAssign.ResetColumns();gridFundToAssign.ResetRows();
Please let me know a solution.
Also, I feel that the InitializeDatasource is making this page very slow. It's getting called on initial page load and then my serverside functions and then rebinding the grid. Instead of giving the speed required with xml features that I tried to use here, looks like the page performance is degraded.
I would like to follow this case. I am having a very similar problem. I am actually using Online Chat right now to try and find the solution.
I am using a SqlDataSource and I have a grid with multiple columns. I have an "Add New Row" button that allows the end user to add a new empty row into the database. The row is being added to the Sql Database with no problems. Once the row is added, I need the grid to "refresh/databind" and show the new blank row. I tried calling uwgMyWebGrid.Databind from the code-behind, but it does not show the new rows in the grid. If I reload/refresh the webpage, then the new rows appear.
Is there any update on this?
Thank you,Wendi