Intersoft WebGrid Documentation
How-to: Set a default value in new row from a button click
See Also Send comments on this topic.

Glossary Item Box

Default value can be set in New Row by using SetText function during onExitEditMode client side event.

This topic will show you how to set default value in WebGrid's new row.

To set a default value in new row from a button click

  1. Drag WebGrid instance into the WebForm.
  2. Add a client side function on your code.
  3. You can set default value in new row by simply using:

    JavaScript Copy ImageCopy Code
    function SelectNewRow()
    {
    var grid = ISGetObject("WebGrid1");
    var newRowElement = grid.RootTable.GetNewRow(); // return the html element of the newrow
    var newRow = grid.RootTable.ToRowObject(newRowElement); // convert to WebGridRow object

    newRow.Select(); // select new row

    var cells = newRow.GetCells(); // populate cells
    cells.GetNamedItem("City").ActivateEdit(); // activate edit cell on City cell, instead of first cell
    cells.GetNamedItem("CustomerID").SetText("NEWCUST", true); // set the CustomerID cell's text to NEWCUST, 2nd parameter is true indicating that the value is same as the text.
    cells.GetNamedItem("Address").SetText("New Address", true);

    newRow.SetDataChanged(); // indicates that this row's data has been changed.
    grid.MarkEdit(); // sets the row's status as edited, as if user has typed inside the cell.
    }

  4. Invoke SelectNewRow() function in a HTML button click.

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.