I have a grid containing say a Customer List and on the same page some controls and a button (Button3).
In the click event handler of Button3, I save a new entry to the database. As such I would need to refresh the grid to reflect that new entry.
The problem is the click event handler is fired after the InitiliazeDataSource event of the webgrid is called.
In the grid's InitiliazeDataSource I simply assign the grid datasource with a dataset (no call to DataBind() is made).
To reflect the newly added entry I tried to reassign the DataSource value with a more updated/latest dataset but it doesn't reflect on the browser. I called DataBind() expicitly and it worked. The only problem is my OnItemCommand event handler for the webgrid no longer triggers right after. I have an aspButton (say ButtonEdit) inside a template column. Whenever an explicit call to DataBind is made clicking ButtonEdit causes a callback but doesn't trigger the OnItemCommand event handler. Since the webgrid has been re-initialized then, succeeding clicks on ButtonEdit will work normally until Button3 is clicked again.
So if I'm not mistaken, calling Grid.DataBind() explicitly in code seems to messes up a lot of things and event handling seems to be one of them. Can someone confirm this? or any work-around? I think this is a common scenario though and calling DataBind over and over again within a postback/callback should in my opinion not cause any issues.
One workaround I could think of is find a way to ensure that my "save" processing comes before InitializeDataSource fires. Ideally it should be on my button click handler which comes unfortunately comes after the InitializeDataSource. This would prevent me from having to fill the dataset more than once nevertheless I think it would be worth looking into.
Thanks in advance for any comment.
Hi,
I have some ideas on this one, but I would need to see some code like the datasource and code behind. You have to be very careful to check when the sqldatasource_selecting event is happening in your page life cycle although it doesn't sound like that is the problem because you would have seen updates on subsequent postbacks.
Ed
I'm having a similar problem.The following did not work for us with a WedDataGrid:WebDataGrid.Rows.Clear()WebDataGrid.Databind()I can't say for sure if it works with a WHDG.
My scenario involves a DropDownList above the WebDataGrid that the user selects. On the postback, I want to alter the SqlDataSource and rebind the updated data to my WebDataGrid. I am not attempting to utilize the filtering built into the WebDataGrid, as the my DropDownList does not contain items found in the WebDataGrid.
I cannot get the data to update in the WebDataGrid for the life of me.
Any help would be greatly appreciated.
Thank You,Mike
I have had a similar problem with the WHDG. Try:
WebDataGrid.Rows.Clear()
WebDataGrid.Databind()
By me, this forces the databind to do it's job.
I'm sad, yet another post on infragistics forum that perfectly describes my problem and it is completely ignored by IG support.
This post 22 months old, is there an answer?
My situation is similar -
on a command button in the grid, I display a web dialog window where the suer enteres some data. On a button click in that WDW, I update my database. Now I want to refresh my webdatagrid, but it fails as described above.
help!
It turns out that the work around mentioned above (eg. perform necessary actions like save before InitializeDataSource is run) won't work all the time. To determine if there is a need to perform such action (eg. save) I was tried to determine the postback control id (using event argument and Request.Forms items which corresponds to button items). It would work generally say when you click on a button on a page you will be able to determine which button was clicked. However when the button is inside another container (eg. UltraWebGrid) it cannot easily be done. It seems that if you have a script manager in the page, Request.Form[0] whose key corresponds to the scriptmanager and whose values to that element which caused the callback. But even then the id returned could be something like ctl00$content$updatepanel1|ctl$ultrawebgrid1$ci_0_6_0$buttonEdit. (button Edit was the clicked button and was inside the template column). It would seem that it's possible to get a reference to that edit button but I think the only way to do that is iterate thru the webgrid's controls (since it store values to viewstate).
Going back to the work around above, the way i did it is to perform the action (eg. delete) in the page's Init event which comes before InitializeDataSource). It is in this Init event that I will need to determine the control clicked and say i need the command argument associated with the button. However, when I iterate thru the control in the webgrid, there are no controls which I believe is because the InitializeDataSource for the web grid has not been called yet. So I have no way to determine which edit button was clicked and what is the commandargument associated with it.
To work around again, when clicking on an edit button i assign a value to a hidden field (to store "commandargument") and use that hidden field in the Init event to perform the deletion before InitializeDataSource so the list will reflect the deleted entry.
Should webgrid allow binding more than once (in one request processing) i would have just bind the grid again after deleting the entry in grid's itemcommand event handler.
A lenghty story there but I think is a fairly common scenario so I hope i'm not missing anything. Any comment would be very much appreciated