SetItem

Description

Sets the value of a row and column in a Web DataWindow client control to the specified value.

Applies to

Web DataWindow client control

Syntax

number objdwcontrol.SetItem ( number row, number column, variant value ) 
number objdwcontrol.SetItem ( number row, string column, variant value ) 

Argument

Description

objdwcontrol

The name of the Web DataWindow client control in which you want to set a specific row and column to a value.

row

The row location of the data.

column

The column location of the data. Column can be a column number or a column name. The column number is the number of the column as it is listed in the Column Specification view of the DataWindow painter—not necessarily the number of the column in the Design view.

value

The value to which you want to set the data at the row and column location. The datatype of the value must be the same datatype as the column.

Returns

Returns 1 if it succeeds and -1 if an error occurs.

Usage

SetItem sets a value in the Primary buffer. It does not affect the value currently in the edit control over the current row and column, which is the data the user has changed or might change. The value in the edit control does not become the value of the DataWindow item until it is validated and accepted (see AcceptText).

You can use SetItem to set the value of an item when the data the user entered is not valid. When you use a return code that rejects the data the user entered but allows the focus to change (return code of 2 in the script of the ItemChanged event or return code of 3 in the ItemError event), you can call SetItem to put valid data in the row and column.

NoteUsing SetItem to correct user input If the DataWindow engine cannot properly convert the string the user entered, you must include statements in the script for the ItemChanged or ItemError event to convert the data and use SetItem with the converted data. For example, if the user enters a number with commas and a dollar sign (for example, $1,000), the DataWindow engine is unable to convert the string to a number and you must convert it in the script.

If you use SetItem to set a row and column to a value other than the value the user entered, you can use SetText to assign the new value to the edit control so that the user sees the current value.

Examples

Example 1

This script fragment checks whether a valid item has been selected before setting the item’s value:

itemValue = objdwProd.GetItem(rowNumber, colName);
if (itemValue == 0) {
   objdwProd.SetItem(rowNumber, colName, 1);
   thePage.submit();
} else if (itemValue == 1) {
   alert(objdwCust.GetItem(1, "custfname") + 
      ", item already selected.");
} else {
alert("Error, item not available.");
}

See also

GetItem