Intersoft WebGrid Documentation
Walkthrough: Modifying other cell values on client side
See Also Send comments on this topic.

Glossary Item Box

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:

 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

  1. Bind WebGrid to AccessDataSource
  2. 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 ImageCopy 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));
            }
        }
    }
    

  3. You can utilize SetText method in order to modify the cell's text, such as following:

    JavaScript Copy ImageCopy 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'");
    }
    
    
    

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.