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
- Drag WebGrid instance into the WebForm.
- Add a client side function on your code.
- You can set default value in new row by simply using:
JavaScript Copy 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.
}
- Invoke SelectNewRow() function in a HTML button click.
Other Resources
Walkthrough Topics
How-to Topics