This walkthrough shows you how to obtain other cells values using client side scripts.
During this walkthrough, you will learn how to do the following:
- Manipulate the grid client side to modify other cell values.
Prerequisites
In order to complete this walkthrough, you will need the following:
- Access to the Microsoft Access Northwind database.
- Visual Studio 2005 Application.
Step-By-Step Instructions
- Bind WebGrid to AccessDataSource.
- Create a HTML button to invoke the clientside function. Notice that by using GetCells method, developers can obtain the cells collection from the WebGridRow object. After the cells collection is obtained, simply utilize GetNamedItem method.
JavaScript Copy Code function GetCellText() { var grid = ISGetObject("WebGrid1"); var curSelObj = grid.GetSelectedObject(); // get selected object if (curSelObj == null) { alert("No row selected. Please select a row"); } else { var row = curSelObj.GetRowObject(); // get the WebGridRow object if (row.Type == "GroupHeader") { alert("Currently selected row is a Group Row. " + "There is no cell information."); } else if (row.Type == "Record") { // obtain WebGridCellCollection of the specified row. var cells = row.GetCells(); // get the address' WebGridCell object by name. var addressCell = cells.GetNamedItem("Address"); alert("Current selected row's Address cell has this text : " + addressCell.Text + "\nThe cell's value is : " + (addressCell.Value == null ? "No Value" : addressCell.Value)); } } }
- You can utilize SetText method in order to modify the cell's text, such as following:
JavaScript Copy Code function UpdateRow() { var grid = ISGetObject("WebGrid1"); // get WebGridRow object by key value. var row = grid.RootTable.GetRowByKeyValue("SPLIR"); var cells = row.GetCells(); row.Select(); // select this row for focus // change contact title cell to Owner cells.GetNamedItem("ContactTitle").SetText("Owner", true); row.Update(); // perform Update alert("ContactTitle of this row has been changed to 'Owner'"); }
Other Resources
Walkthrough Topics
How-to Topics