Mark all the child rows as checked if the CheckBox in the owning parent row is checked. This task is done by using client-side script.
During this walkthrough, you will learn how to do the following:
- Using CheckBox column in hierarichal WebGrid.
- Use WebGrid's InitializeRow to set the row conditions.
- Using Client Side events.
Prerequisites
In order to complete this walkthrough, you will need the following:
- Visual Studio 2005 Application.
Step-By-Step Instructions
To create new application and mark all the child rows
- Binding WebGrid to Hierarchical ISDataSource.
- Create a hierarchical grid with one column of each table is set to CheckBox column type and name the columns as 'CheckBoxColumn'.
- Attach the 'onclick' attributes to the parent CheckBox column in InitializeRow event.
C# Copy Code private void WebGrid1_InitializeRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e) { if (e.Row.Table.DataMember == "Customers") { e.Row.Cells.GetNamedItem("CheckBoxColumn").CustomObjectAttributes = "onclick='doChecking(this)'"; } }
- Apply the following script to the page:
JavaScript Copy Code var row = null; var IsExpandedByCheck = false; function doChecking(obj) { var grid = ISGetObject("WebGrid1"); row = grid.GetSelectedObject().GetRowObject(); // expand the row if it's not yet expanded if (!row.ChildExpanded) { IsExpandedByCheck = true; row.ExpandChildRow(); } else { // if it's already expanded.. MarkChildRows(row, obj.checked); } } // mark the child rows after being expanded function WebGrid1_OnAfterResponseProcess(gridId, action, lastRO, xmlRO) { if (action == "LoadChild" && IsExpandedByCheck) { MarkChildRows(row, true); IsExpandedByCheck = false; row = null; // reset row } return true; } function MarkChildRows(row, checked) { var childRows = row.GetChildRows(); // get the child rows for (var i=0; i<childRows.length; i++) { if (childRows[i].GetElement().type == "Record") { var cell = wgGetCellByName(childRows[i].GetElement(), "CheckBoxColumn"); cell.childNodes[0].checked = checked; } } }
- Register the WebGrid1_OnAfterResponseProcess function to the grid's OnAfterResponseProcess client-side event.
Tasks
Walkthrough: Utilizing button ColumnType
Walkthrough: Utilizing various ColumnTypes
Walkthrough: Deleting a record using WebGrid button
Walkthrough: Configuring password as ColumnType
Concepts
Column Types
References
ColumnType Property
InitializeLayout Event
ClientEvents Class
Other Resources
Walkthrough Topics
How-to Topics