Hello,I have been reading all the post an example about hierarchical webgrid.However, you guys are always using a different method to bind the gridSo what is the most efficient way to bind my hierachical webgrid? (ondatabinding event? page_onload? initializedatasource?)
Keep in mind that I want to do update,insert and delete in my webgrid. By the way, other than the WHDS, you guys did not find any other way to handle CRUD activity more efficiently? I have to write way more code than with the CLR 1.0 to get the CRUD working. The WHDS still has some bug so I have to do it manualy. So if you have any better method please let me know.Thanks and merry christmas
arnololo said:I can not seem to be able to force the grdi bind twice, once after the initialize datasource and once after my listview event slectedindexchanged.
arnololo said:With regards to the expandall, I have to have it expanded so from what you said I guess I can not use the loadondemand. I wanted to use it because I have a lots of row to display. Is there another to load all the rows in the background, I mean that the grid shows the first rows and in the background, the rest of the rows are added.
I can not seem to be able to force the grdi bind twice, once after the initialize datasource and once after my listview event slectedindexchanged.
I put the following code in the selectedindexvhange but the grid does not refresh.UW.DataSource = Data.Tables["parent"].DefaultView;UW.DataBind(); The grid always shows an item selected behind.With regards to the expandall, I have to have it expanded so from what you said I guess I can not use the loadondemand. I wanted to use it because I have a lots of row to display. Is there another to load all the rows in the background, I mean that the grid shows the first rows and in the background, the rest of the rows are added.Thanks
If you absolutely need to control the time when the grid is databound, then you don't want to use either ASP.NET DataSource objects or the InitializeDataSource event. Of course, to use the grid's AJAX functionality, you need to use one or the other of these approaches.
The way I get around this is to use a flag (either a session variable, hidden field, or other control's value) to determine what I need to bind to in the InitializeDataSource event. I simply need to make sure this flag is changed upon the correct conditions (such as the SelectedIndexChanged event of a ListView) and then manually re-bind the grid.
The result is that the grid is bound twice - once in InitializeDataSource to its previous data source, then again to the new data source. This is necessary when the grid's AJAX functionality is enabled, since the grid doesn't store its data in ViewState and must re-create its "before" state from its data source to be able to process changes.
Regarding your question about the ExpandAll() method and load-on-demand, I generally suggest against using the two together. Expanding a record on the server does not triggre the load-on-demand of its child records; it's up to the application developer to add the child records to the grid manually. You'd essentially need to load all of the data to the grid in order to expand all records, which defeats the purpose of using load-on-demand (whether XML, manual, or automatic). If you're only using XML load-on-demand to get AJAX-enabled updates, I suggest wrapping your grid in either a WebAsyncRefreshPanel or an UpdatePanel instead.
Thanks for your answer,the problem with using InitializeDataSource is that I do not have anymore control over when the grid get databound.I have a listview and based on the element selected on the listview I refresh my grid.
This works good if I manually bind the datagrid at, Page_unload or ListView1_SelectedIndexChanged. But If I use the InitializeDataSource the grid is always bound to0 early. What I mean is that if I change the selected item in my listview then the grid would always be one selection behind because the grid goes first to the InitializeDataSource and then my ListView1_SelectedIndexChanged get hit which is too late.Would you have a solution for that?Also how can I use the expandall set to true when I use loadOnDemand?
thanks and merry christmas
The "most efficient way" is .... it depends. It depends greatly on the type of object you're using for your grid's data source, the nature of the data it contains, and the grid options you're using.
For my personal usage, unless I have a specific reason to do otherwise, I use one of two approaches. One is to assign a data source at design time, such as when I'm using an ASP.NET DataSource control (SqlDataSource, WebHierarchicalDataSource, and so on). If I'm binding to an object in code, I prefer using InitializeDataSource. With either approach, I can easily turn on the grid's AJAX functionality without making significant code changes.
For hierarchical data, if you want to bind at design-time, then WebHierarchicalDataSource is your only viable approach; most of the other ASP.NET DataSource controls (including SqlDataSource and ObjectDataSource) can't handle a hierarchy. If you want to bind in code, you can use the UpdateRow and DeleteRow events (or their batch equivalents) to update your data object, in the same way that was required in a CLR 1.x application.