Hi All,
Could anyone please help me when to use GridRecordCollection and GridRecordItemCollection? I'm using Infragistics 2012.2 to create a webhierarchialdatagrid dynamically as a usercontrol and shall be using this user control in some other pages.
What is the equivalent of UltraGridRow of UltraWebGrid in WebHierarchialDataGrid? Should I use GridRecord or GridRecordItem? Kindly clarify..
Hello Pavan,
If you are looking for a comparison or equivalence I will suggest taking a look in this topics:
Migrating from UltraWebGrid to WebDataGrid and WebHierarchicalDataGrid
UltraWebGrid to WebDataGrid Migration
Furthermore GridRecord is a record or row in the WebDataGrid control, GridRecordItem represents a record item or cell in the WebDataGrid control. The WebHierarchicalDataGrid control is built upon WebDataGrid. The WebHierarchcalDataGrid creates a collection of ContainerGrid objects to display the different hierarchical views. These objects can have child ContainerGrid objects of their own. You can access a row’s child ContainerGrid objects by using the ContainerGridRecord. For more information take a look at the help topic:
https://www.infragistics.com/help/aspnet/webhierarchicaldatagrid-about-webhierarchicaldatagrid
Hello Nick,
Thank you for your prompt response!
Let me put my futher questions wrt UltraWebGrid migration to WebHierarchialDataGrid. I'm using below members in my project to create Rows and Row Items with UltraWebGrid currently. How do I replace these with WebHierarchialdDataGrid members? Please guide me on this..
//Rows collection of UltraWebGrid
RowsCollection ChildrenUnderlyingRows { get; }
//Underlying Row
private UltraGridRow underlyingRow;
// Create the underlying row - UltraWebGrid Row creation UltraGridRow childUnderlyingRow = new UltraGridRow();childUnderlyingRow.Key = key;
//To read a cell from the row
UltraGridCell cellToUpdate = underlyingRow.Cells.FromKey(cellKey);
I've replaced the above methods with below ones:
//RowsCollection has been modified with ContainerGridRecordCollection.
ContainerGridRecordCollection ChildrenUnderlyingRows { get; }
//UltraGridRow has been replaced with ContainerGridRecord
private ContainerGridRecord underlyingRow;
//To read a cell from the grid, replaced it with GridRecordItem
GridRecordItem cellToUpdate = underlyingRow.Items.FindItemByKey(cellKey);
But for this snippet, I'm not able to understand and find a replacement.
Are Key and Datakey one and the same? If you want I shall zip the file and attach with this thread.
Kindly guide me on this migration.
Thanks,
Pavan.P
Pavan,
It will be better to take a step back and consider what you need to accomplish with the WebDataGrid or WebHierachicalDataGrid rather than looking at your existing code and asking how to accomplish the same. For example the first piece of code is how to dynamically create grid row objects and set their value and the answer is that the WebDataGrid and WebHierarchicalDataGrid have a different architecture where they require that you are always bound to data while the UltraWebGrid allowed the dynamic creation of the rows without a data source. So to dynamically add rows to the grid you will need to dynamically build a List or DataTable and bind that to the WebDataGrid instead.
This is why you weren't able to find an approach to dynamically crate the GridRecord (or equivalent to the UltraGridRow).
I recommend that you take a step back and look at the features and functionality that you want from the WebDataGrid/WebHierarchicalDataGrid and what is the best approach to accomplish that with the new control (to you). Once you have then, then take a look at your code and see what makes sense to reuse and what should be rewritten because the approach needs to change.
Let us know if you have any questions.
Hi Alan,
Thanks for the response!
I understood the whole context from your reply. Let me putforth my points of concern and I request you to kindly guide me a way to break this.
1. I've a user control built on UltraWebGrid with hierarchial display and a bunch of several other features. I was asked to migrate this user control from Infragistics V 9.2 to V 2012.2. The above code snippets I cited in my earlier post were of this user control only. As the architecture has been changed completely and now i cannot add rows to the grid in 2012.2, What approach do you suggest me to replicate the older features in the new grid?
2. I just want to migrate the user control with WebHierarchialDataGrid control without breaking any of the client side events.
3. This user control has classes for creating Rows and adding them to the grid, user can add multiple columns with their respective rows/cells to the grid to enter the data (CRUD operations).
Now, I'm thinking of eliminating all the row related operations in the user control and surprised how to handle row add functionality to the grid as row addition is purely dynamic.
Please suggest me an approach so that I can go ahead in that way with successful migration.
Awaiting your response on this Alan.
Thanks,Pavan.P
How to approach this may depend on how many controls are on the user control as well as what the public API the user control is exposing for your application. If the user control only contains the grid or just a few small additional controls, it may be simpler to write a new user control that has the same public API. If your user control actually exposed the instance of the UltraWebGrid or it's client events directly to the rest of your application, then replacing the grid will be more complex as you will likely need to change more of your application than just the UserControl.
If you are exposing the client side events of the grid or other retired controls directly, using the existing code in your application outside of the user control not be possible as the objects from the old UltraWebGrid control simply will not exist anymore. If this is the case, consider what you do want to be the public API of your user control and create the appropriate abstractions within the UserControl now so that the page or user control using this user control truly doesn't know about its internal implementation.
As far as how to approach adding rows to the user control containing the WebDataGrid, this is still difficult to answer without knowing the specifics of how the UserControl is used. For dynamic column creation, you would probably want to use a DataTable/DataSet and build it dynamically in the user control and then bind the grid to that DataTable/DataSet. One challenge is that you would need to bind the WebDataGrid to the same data source on each post to the server so you need to be able to recreate it.
Some other factors that impact the best approach to take include:
If you don't need AJAX functionality and all of the interactions with the grid are isolated to within the UserControl and the rest of the application is expecting it to act as a store of the data across post backs, I would probably use a DataSet/DataTable within the UserControl and store it in ViewState so that I could bind to the same data across post backs in Page Load. For that to work well, I would use Batch Updating and make sure no AJAX functionality is enabled.
Another good question is, do you really need to migrate the UserControl to 12.2? It may be possible to use the UltraWebGrid from 11.1 in the same application that is using the newer 12.2 controls if you aren't actually having issues with using it. Depending on the expected lifecycle of your application, maybe that is a better option if the application will not be around much longer. The Classic Control Migration Guide is a good starting point to see if this is a good option for you.
Let me know if you have any questions with this matter.
Dear Alan,
Thanks for the reply!
0546A52EF7F61F69CA29B4B6634A1B420FD68C22 said:Are you using any AJAX functionality?
No
0546A52EF7F61F69CA29B4B6634A1B420FD68C22 said:Is the UserControl expected to round trip its own data to and from the client across multiple post backs
No, The user control is just a skeleton in creating a basic grid with feasability to add multiple columns and rows
0546A52EF7F61F69CA29B4B6634A1B420FD68C22 said:Do you allow editing of the data or is it read only?
Yes, Edit functionality is handled via client side events on top of this user control independently
0546A52EF7F61F69CA29B4B6634A1B420FD68C22 said:What other features of the grid are you using? Filtering, Sorting, Grouping?
None of these features are being used.
I was able to modify the user control that makes use of Infragistics 9.2 UltraWebGird with Hierarchial viewtype to WebHierarchialDataGrid 2012.2 without any compile time errors . But,,...
I'm confused with the usage of ContainerGrid and WebHierarchicalDataGrid, In the earlier code i see only UltraWebGrid with UltraGridRows and UltraGridColumns in the code, I tried replacing the UltraWebGrid with ContainerGrid and noticed that the control is null. Would you please guide me here on the WebHierarchicalDataGrid architecture.. Below is the sample code,
I understood that parent datasource should be given to webhierarchicaldatagrid and child datasource should be bound to the containergrid, In my case i'm confused which one to use in the given sample code below. If you can guide me understanding this, It would be very helpful for a successful migration of the user control.:)
Thank you!
/// <summary> /// Gets the ultra web grid. /// </summary> /// <value>The ultra web grid.</value> private ContainerGrid GridControl { get { return (ContainerGrid)FindControl("UltraWebGrid"); } } /// <summary> /// The underlying grid wrapped by the budgeting grid. /// </summary> //private UltraWebGrid underlyingGrid; private ContainerGrid underlyingGrid; /// <summary> /// Initializes a new instance of the <see cref="BudgetingGrid"/> class. /// </summary> /// <param name="page">The page in which the budgeting grid is displayed.</param> /// <param name="ultraWebGrid">The underlying ultra web grid wrapped by the budgeting grid.</param> public BudgetingGrid(Page page, ContainerGrid ultraWebGrid) { InitializeFields(); this.page = page; this.underlyingGrid = ultraWebGrid; }
In the code provided, the UltraWebGrid was returned by the GridControl property in the past and this would be the WebHierarchicalDataGrid in this scenario.
Assuming this code is for the UserControl that you mentioned you are upgrading, it seems that the scope of the change will be beyond just the UserControl since it appears to take the instance of the grid in the constructor and exposes it as a property.
That being said if the UserControl is truly wrapping our control, you should consider refactoring your code so that the grid is created within the UserControl and not exposed as a property to the rest of the application so that the logic related to the grid is encapsulated within the UserControl.
As far as a better understanding the WebHierarchicalDataGrid and what a ContainerGrid is, start with the About WebHierarchicalDataGrid topic in the help.
Thanks for the links you provided! I was able to migrate from Infragistics 9.2 UltraWebGrid to 2012.2 WebHierarchicalDataGrid with some of the features left behind.
I'm able to create columns and bands from the codebehind(Existing code) with modifications.
It would be great if you can guide me for the below scenarios.
//Logic to createor add new UltraWebRow to the UltraWebGrid BudgetingGridModel.Row firstRow = budgetingGridTest.GetOrCreateRow("1", BudgetingGridModel.Row.RowTypes.RollUp, delegate(BudgetingGridModel.Row createdRow) { createdRow.LastActualsMonth = 7; //createdRow.UnderlyingRow.Cells.FromKey("First").Text = "1"; createdRow.UnderlyingRow.Items.FindItemByKey("First").Text = "1"; }); public static BudgetingGrid.Row GetOrCreateRowImplementation(this IRowContainer rowContainer, string key, BudgetingGrid.Row.RowTypes type, bool rollUpAmountsToParentRow, BudgetingGrid.Row.RowCreatedHandler rowCreatedHandler, BudgetingGrid.Row.RowCompareHandler rowCompareHandler) { // Try getting the row first BudgetingGrid.Row row = rowContainer.GetRow(key); BudgetingGrid grid = null; // Create the row if it doesn't exist if (row == null) { // Create the underlying row //UltraGridRow childUnderlyingRow = new UltraGridRow(); //childUnderlyingRow.Key = key; GridRecord childUnderlyingRow = new GridRecord(); childUnderlyingRow.DataKey[0] = key;
I know that we cannot create a Row from the codebehind in the new Grid. How can I bind already created columns and bands along with the new rows to the Grid? I need to replace the GetOrCreateRow method, But puzzled how to do this dynamically from codebehind.
Note: To test the rendering of Grid, I've a test project aspx page, From code behind, I'm creating Columns, Rows, bands, respective styling to make sure everything is working.
Please help me in
Kindly acknowledge. I shall provide the code if you need.
As the grid is always bound to a data source, the question isn't so much how to add rows to the grid as it is how to add/get rows to/from the data source that the grid is bound to. The best approach for this will vary depending on the data source that you are using. If you are using a DataSet with DataTables then you would interact with the DataSet directly and the grid control used isn't really relevant to the add and get methods that you have here.
What may be more important is timing for when you are are adding and getting the rows compared to when you are binding the grid to the data source.
For your specific questions:
Let me know if you have any questions.
Many thanks for the reply! Sorry if I'm troubling you much..
0546A52EF7F61F69CA29B4B6634A1B420FD68C22 said:How to bind already columns with bands along with the newly created rows to the grid? - Not 100% sure what is meant here, it sounds as though you are appending data to a grid that already contains data. If this is on the initial request, add the rows before you set the data source of the grid. If this is on subsequent requests, how are you persisting the data across post backs? Is that a responsibility of the UserControl? If yes, one of the simplest solutions is to store the data source you are bound to in view state if it support serialization like a DataSet does.
I'm attaching my .cs file herewith, I'm creating the 2 columns and 2 bands from the code behind, Later as you suggested, I've created a dataset with rows and columns and giving it as data source to the gird. But this fails with the error "In order to use load-on-demand DataKeyFields need to be set for each parent Band." I'm not sure what is going wrong here.
While creating bands, I'm adding the datakeys and datamember to the band.
protected void Page_Load(object sender, EventArgs e) { budgetingGridTest.Height = 150; budgetingGridTest.BudgetingYear = 2010; budgetingGridTest.FirstYearToDisplay = 2009; budgetingGridTest.LastActualsMonth = 11; budgetingGridTest.NumberOfYearsToDisplay = NumberOfYearsToDisplay; budgetingGridTest.NumberOfYearsOfMonthlyBasedAmounts = 2; budgetingGridTest.DisplayColumnForFutureYears = true; budgetingGrid2.Height = 150; budgetingGrid2.BudgetingYear = 2010; budgetingGrid2.FirstYearToDisplay = 2009; budgetingGrid2.LastActualsMonth = 11; budgetingGrid2.NumberOfYearsToDisplay = 4; budgetingGrid2.NumberOfYearsOfMonthlyBasedAmounts = 2; // First BudgetingGridModel.Band firstBand = budgetingGridTest.AddNewBand("First", "first"); BudgetingGridModel.Column firstColumn = firstBand.AddNewColumn("First"); firstColumn.OverrideWidth(150); BudgetingGridModel.Band firstBand2 = budgetingGrid2.AddNewBand("First", "first"); BudgetingGridModel.Column firstColumn2 = firstBand2.AddNewColumn("First"); firstColumn2.OverrideWidth(150); // Second BudgetingGridModel.Band secondBand = budgetingGridTest.AddNewBand("Second", "second"); BudgetingGridModel.Column secondColumn = secondBand.AddNewColumn("Second"); secondColumn.OverrideWidth(115); BudgetingGridModel.Band secondBand2 = budgetingGrid2.AddNewBand("Second", "second"); BudgetingGridModel.Column secondColumn2 = secondBand2.AddNewColumn("Second"); secondColumn2.OverrideWidth(115); //Comment BudgetingGridModel.Column commentColumn = budgetingGridTest.AppendNewColumn("Comment", BudgetingGridModel.Column.ColumnTypes.EditableText); commentColumn.OverrideWidth(200); commentColumn.HeaderCaption = "Comment"; BudgetingGridModel.Column commentColumn2 = budgetingGrid2.AppendNewColumn("Comment", BudgetingGridModel.Column.ColumnTypes.EditableText); commentColumn2.OverrideWidth(200); commentColumn2.HeaderCaption = "Comment"; // Delete BudgetingGridModel.Column deleteColumn = budgetingGridTest.AppendNewColumn("Delete", BudgetingGridModel.Column.ColumnTypes.Custom); deleteColumn.OverrideWidth(100); deleteColumn.HeaderCaption = "Delete"; BudgetingGridModel.Column deleteColumn2 = budgetingGrid2.AppendNewColumn("Delete", BudgetingGridModel.Column.ColumnTypes.Custom); deleteColumn2.OverrideWidth(100); deleteColumn2.HeaderCaption = "Delete"; if (ViewState["Initialized"] == null) { budgetingGridTest.CreateStructure(); budgetingGrid2.CreateStructure(); //This is the method we used to create rows andadd it the ultrawebgrid.. / / / first //BudgetingGridModel.Row firstRow = budgetingGridTest.GetOrCreateRow("1", BudgetingGridModel.Row.RowTypes.RollUp, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.LastActualsMonth = 7; // //createdRow.UnderlyingRow.Cells.FromKey("First").Text = "1"; // createdRow.UnderlyingRow.Items.FindItemByKey("First").Text = "1"; // }); //budgetingGridTest.UnderlyingGrid.DataSource = PopulateGrid(); DataTable table = new DataTable(); table.Columns.Add("Dosage", typeof(int)); table.Columns.Add("Drug", typeof(string)); table.Columns.Add("Patient", typeof(string)); table.Columns.Add("Date", typeof(DateTime)); // Here we add five DataRows. table.Rows.Add(25, "Indocin", "David", DateTime.Now); table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now); table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now); table.Rows.Add(21, "Combivent", "Janet", DateTime.Now); table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now); budgetingGridTest.UnderlyingGrid.DataSource = table; budgetingGridTest.UnderlyingGrid.DataBind(); //BudgetingGridModel.Row firstRow2 = budgetingGrid2.GetOrCreateRow("1", BudgetingGridModel.Row.RowTypes.RollUp, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.LastActualsMonth = 7; // createdRow.UnderlyingRow.Items.FindItemByKey("First").Text = "1"; // }); //// second //BudgetingGridModel.Row firstRowChildRow = firstRow.GetOrCreateRow("1.1", BudgetingGridModel.Row.RowTypes.Editable, true, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.UnderlyingRow.Items.FindItemByKey("Second").Text = "1.1"; // }); //firstRow2.GetOrCreateRow("1.1", BudgetingGridModel.Row.RowTypes.Editable, true, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.UnderlyingRow.Items.FindItemByKey("Second").Text = "1.1"; // }); //// first //BudgetingGridModel.Row secondRow = budgetingGridTest.GetOrCreateRow("2", BudgetingGridModel.Row.RowTypes.RollUp, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.UnderlyingRow.Items.FindItemByKey("First").Text = "2"; // }); //BudgetingGridModel.Row secondRow2 = budgetingGrid2.GetOrCreateRow("2", BudgetingGridModel.Row.RowTypes.RollUp, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.UnderlyingRow.Items.FindItemByKey("First").Text = "2"; // }); //// Second //BudgetingGridModel.Row secondRowChildRow = secondRow.GetOrCreateRow("2.1", true, // delegate(BudgetingGridModel.Row createdRow) // { // createdRow.UnderlyingRow.Items.FindItemByKey("Second").Text = "2.1 <em>(readonly)</em>"; // }); //firstRowChildRow.AddFutureYearsAmount(12345); //secondRowChildRow.SetMonthlyAmount(2010, 8, 1984); //secondRowChildRow.AddFutureYearsAmount(123456); //secondRowChildRow.SetCellContent("Delete", "<marquee><a href=\"#\">Test to see if HTML markup can be used</a></marquee>"); ViewState["Initialized"] = true; } }
PS : Couldnt attach as I didnt find any link. Request you to kindly guide me on this.
Thanks much!
I've created 2 bands and 2 columns in the above code, But how can I add these already created columns to the data table and bind it to the grid>? How to add the created columns to the data table along with new data rows? I hope my question is clear now.
Thanks!
It would appear that the AddNewBand and AddNewColumn methods are part of your framework so it is difficult to understand what is expected from these without the code for them.
As far as adding Columns to a DataTable, you would just add a DataColumn to the Columns collection of the DataTable. For adding rows, you simply add rows to the DataTable using the Rows collection. All of this should be done before setting the DataSource of the WebDataGrid ideally.
The Data Binding topic for the WebHierarchicalDataGrid has some details on the DataKeyFields property. Since it isn't set in the code provided, you may just need to set it to the primary key of the DataTable. Note that for hierarchical data there should be a key field in the parent and you would be setting the DataKeyFields property to the key of that Column in the parent DataTable.
On attaching files, use Insert -> Insert image/video/file at the bottom of the editor when typing your post or reply.