Spread for ASP.NET 11 Product Documentation
SetForeColor
Spread for ASP.NET 11 Product Documentation > Client-Side Scripting Reference > Scripting Members > Methods > SetForeColor

Sets the forecolor of the cell at the specified row and column.

Syntax

[JavaScript]

FpSpread1.SetForeColor(row,column,value,noEvent);

Parameters

row
Integer, row index
column
Integer, column index
value
String, value
noEvent
Boolean, whether to trigger the onDataChanged event

Return Type

None

Remarks

This method sets the color of a cell at the specified row and column and triggers the onDataChanged event if specified. If noEvent is true, the method does not trigger an event; otherwise, the method triggers an onDataChanged event. This method does not cause a postback to occur.

Example 1

This is a sample that contains the method.

On the server side on page load:

Code
Copy Code
FpSpread1.Attributes.Add("onDataChanged", "ProfileSpread(event)")

On the client side, the script that contains the method would look like this:

JavaScript
Copy Code
<script lang="javascript">
   function ProfileSpread(event)
   {
      var szCell = document.all("FpSpread1");
      if (szCell.ActiveCol == 0)
      {
         szCell.Cells(0,1).SetForeColor("red",true);
         alert("Test");
      }
   }
</script>

Example 2

This example maps the onDataChanged event and updates the cell forecolor when a value is changed.

JavaScript
Copy Code
<script language="javascript" type="text/javascript">
  window.onload = function () {
    var spread1 = document.getElementById("<%=FpSpread1.ClientID %>");
    if (document.all) {
// IE
    if (spread1.addEventListener) {
// IE9
    spread1.addEventListener("DataChanged", dataChanged, false);
  } else {
// Other versions of IE and IE9 quirks mode (no doctype set)
    spread1.onDataChanged = dataChanged;
  }
}
  else {
// Firefox
  spread1.addEventListener("DataChanged", dataChanged, false);
  }
}
function dataChanged(event) {
  FpSpread1.Cells(FpSpread1.ActiveRow, 2).SetForeColor("red", true);
}
</SCRIPT>